O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required