Name

for

Synopsis

                     
                        for
                      
                     x [
                        in
                      
                     list]
  
                        do
                     
                     commands
                     
                        done
                     

Assign each word in list to x in turn and execute commands. If list is omitted, $@ (positional parameters) is assumed.

Examples

Paginate all files in the current directory and save each result:

                     for file in *
    do
         pr $file > $file.tmp
    done

Search chapters for a list of words (like fgrep -f):

                     for item in 'cat program_list'
    do
         echo "Checking chapters for"
         echo "references to program $item..."
         grep -c "$item.[co]" chap*
    done

Get Mac OS X Tiger in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.