Shell Tricks

A few days back, I was writing a script to unlock all my salary slips which were password protected .rar files. While writing that script, I had to iterate to a while loop reading each line at a time from a file. I forgot that syntax, and I did some googling to get the syntax. Here how it was:

ls > /tmp/chmod_many.sh.tmp
while read line
do
echo $line
done < /tmp/chmod_many.sh.tmp

Now, to eliminate the need of the temporary file, here is another version of the script:

ls | while read line
do
echo $line
done

Isn’t it awesome!! :)

Advertisements

2 thoughts on “Shell Tricks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s