9.9.3 for and foreach
do
command list
done
The list_of_values is optional, with $@ assumed if nothing is specified. Each value in this list is sequentially substituted for variable until the list is emptied. Wildcards can be used and are applied to file names in the current directory. Below we illustrate the for loop in copying all files ending in .old to similar names ending in .new. In these examples the basename utility extracts the base part of the name so that we can exchange the endings.
#!/bin/sh
for file in *.old
do
newf=`basename $file .old`
cp $file $newf.new
done