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.
Here’s a basic while loop. The test condition ...