The until loop executes a series of commands until the condition is true and stops. The until loop is the exact opposite of the while loop. While loops are generally preferred over until loops, there are times, and only rare cases, where until loops are more useful.
The until loop format is:
For example, use the until command to output numbers from 0 to 9:
The until loop format is:
until command do Statement(s) to be executed until command is true doneCommand is generally a conditional expression. If the return value is false, it will continue to execute the statement in the loop body, otherwise it will jump out of the loop.
For example, use the until command to output numbers from 0 to 9:
#!/bin/bash a=0 until [ ! $a -lt 10 ] do echo $a a=`expr $a + 1` doneoperation result:
0 1 2 3 4 5 6 7 8 9