9. ’Round and ’Round She Goes

In this chapter you’ll learn how to set up program loops. These loops will enable you to execute repeatedly a set of commands either a specified number of times or until some condition is met. The three built-in looping commands are

for

while

until

You’ll learn about each one of these loops in separate sections of this chapter.

The for Command

The for command is used to execute a set of commands a specified number of times. Its basic format is as shown:

for var in wordl word2 ... wordndo         command                  command         ...done

The commands enclosed between the do and the done form what’s ...

Get Unix Shell Programming, 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.