Software >> OS >> Unix >> Shell >> Commands >> for >> Examples of how to use for

(1)   Process files that match a wildcard

e.g. count the number of lines for each file that starts with q

# for f in `ls -1 q*`;do wc -l $f;done;

or

# for f in q*; do wc -l $f;done;

 

(2)   Run some command using a loop counter.  In this case for every count, we run echo $i and then sleep for 5 seconds.

# for i in {1..10};do echo $i;sleep 5;done;