Читать книгу Linux Bible - Christopher Negus - Страница 210
The ″while…do″ and ″until…do″ loops
ОглавлениеTwo other possible looping constructs are the while…do
loop and the until…do
loop. The structure of each is presented here:
while condition until condition do do { body } { body } done done
The while
statement executes while the condition is true. The until
statement executes until the condition is true—in other words, while the condition is false.
Here is an example of a while
loop that outputs the number 0123456789:
N=0 while [ $N -lt 10 ] ; do echo -n $N let N=$N+1 done
Another way to output the number 0123456789 is to use an until
loop as follows:
N=0 until [ $N -eq 10 ] ; do echo -n $N let N=$N+1 done