44.10 Loops That Test Exit StatusThe Bourne shell has two kinds of loops that run a command and test its exit status. An until loop will continue until the command returns a zero status. A while loop will continue while the command returns a zero status. 44.10.1 Looping Until a Command SucceedsThe until loop runs a command repeatedly until it succeeds. That is, if the command returns a non-zero status, the shell executes the body of the loop and then runs the loop control command again. The shell keeps running the command until it returns a zero status, as shown in the following example: % The loop runs
who
(51.4
)
and pipes that output to
grep
(27.1
)
,
which searches for any line starting with barb
and a space.
(The space makes sure that usernames like barbara
don't match.)
If grep
returns non-zero (no lines matched), the shell waits 60
seconds. Then the loop repeats, and the script tries the
[A Bourne shell until loop is not identical to the until construction in most programming languages, because the condition is evaluated at the top of the loop. Virtually all languages with an until loop evaluate the condition at the bottom. -ML ] 44.10.2 Looping Until a Command Fails
- |
|