O'Reilly logo

Mac OS X Tiger in a Nutshell by Jason McIntosh, Chuck Toporek, Chris Stone, Andy Lester

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required