18.7. while loop

The while loop is used conditionally to execute a series of commands. It is also used to read data from a input file. The format of the while loop is:

while command do   commands1   commands2  ... done 

Several commands can be placed between the while and do, though generally only one is used, and the command is usually a test condition.

The commands after the do and up to the done will be executed only if the exit status of the command is zero; if the exit status is anything else, the loop will terminate.

When the commands have been executed, control is returned back to the top of the loop to start all over again until the condition of the test is a non-zero.

18.7.1. Simple while loop

Here’s a basic while loop. The test condition ...

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