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.
- I have a folder with a lot of files.
- One of the file contains the string “1362803524”.
- 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.