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:
for file in $(find . -name "*.c" -print)
do
    if test $file -ot $1
    then
        echo $file
        c89 -c $file
    fi
done

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 for 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.

For more information about thetest command, see z/OS UNIX System Services Command Reference. The section that discusses reserved words in contains information about the [[ ... ]] form.

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014