Shell Learning 19 - Shell until loop

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:
until command
do
Statement(s) to be executed until command is true
done
Command 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`
done
operation result:
0
1
2
3
4
5
6
7
8
9

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325722006&siteId=291194637