z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Combining control structures

z/OS UNIX System Services User's Guide
SA23-2279-00

You can combine control structures by nesting (that is, putting one inside another). For example:
foreach file ( `find . -name "*.c" -print` )
        if ( -M $file > -M $1 ) then
                echo $file
                c89 -c $file
        endif
end
This shell script takes one positional parameter, giving the name of a file. The script looks in the working directory and finds the names of all .c files. The if control structure inside the foreach loop tests each file to see if it is older than the file named on the command line. If the .c file is older, echo displays the name, and the file is compiled. You can think of this as making a set of files up to date with the file name specified on the command line.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014