Q. How do I run shell loop over set of files stored in a current directory or specified directory?
A. You can use for loop easily over a set of shell file under bash or any other UNIX shell using wild card character.
You can use shell variable to store all file names. For example, store all *.c file in a variable called FILES:
$ FILES="*.c"
Now to loop through all files, enter:
$ for f in "$FILES"; do echo "Processing $f file.."; done
#!/bin/bash FILES="*" for f in "$FILES" do echo "Processing $f file..." # take action on each file. $f store current file name cat $f done
This article is from http://www.cyberciti.biz/faq/bash-loop-over-file