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/foreach 
loops
for variable in ...

Get Solaris™ 8 Advanced System Administrator's Guide, Third Edition 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.