Controlling the Flow

You can use loops to control the flow of execution in a script. A loop is an iterative mechanism that repeats a sequence of instructions until a predetermined condition is met. You can use different forms of loops. The for/foreach loop executes a list of commands one time for each value of a loop variable. The while loop repeatedly executes a group of commands within the body of the loop until the test condition in the expression is no longer true. The Bourne and Korn shells provide an until loop that continues to execute until a command executes successfully. Table 97 shows the syntax for for/foreach, while, and until loops.

Table 97. Looping Syntax
Feature Bourne/Korn Shell C Shell
for variable in ...

Get Solaris™ 8 Advanced System Administrator's Guide, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.