Unix Korn Shell Scripting – For Loop + If else

Unix Korn Shell Scripting – For Loop + If else

Shell Scripting is a very important skillset of any Unix/Linux administrator.  As a general rule of thumb. anything that you need to do more than once, you should script it. However, the only way to pick up shell scripting is to practice and practice! You can’t just read a textbook and declare that you know scripting. It takes practice and experience to be proficient in it.

This is one of my attempt to practise shell scripting.

  1. I have a folder with a lot of files.
  2. One of the file contains the string “1362803524”.
  3. I need to find out which file contains the strings.

 

for files in $(ls)
do
strings $files | grep -i 1362803524
if [ $? = 0 ]
then
echo $files
fi
done
1365863531^1^^.zip
yzzz130467.tar

I know this is a really simple shell script, but it’s something that I came up with.

Advertisements

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