Unix for Beginners
Unix Shell Programming
Advanced Unix
Unix Useful References
Unix Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM
|
Unix Shell - The until Loop
The while loop is perfect for a situation where you need to execute a set of commands while some condition is true. Sometimes you need to execute a set of commands until a condition is true.
Syntax:
until command
do
Statement(s) to be executed until command is true
done
|
Here Shell command is evaluated. If the resulting value is false, given statement(s) are executed. If command is true then no statement would be not executed and program would jump to the next line after done statement.
Example:
Here is a simple example that uses the until loop to display the numbers zero to nine:
#!/bin/sh
a=0
until [ ! $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
|
This will produce following result:
|
|
|