Linux Know-How provides a collection of introductory texts on often needed Linux skills. |
![]() |
Home ![]() ![]() ![]() |
||
See also: The for loop, The while loop | ||
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
||
The until loopThe until loop is very similar to the while loop, except that the loop executes until the TEST-COMMAND executes successfully. As long as this command fails, the loop continues. The syntax is the same as for the while loop: until TEST-COMMAND; do CONSEQUENT-COMMANDS; done The return status is the exit status of the last command executed in the CONSEQUENT-COMMANDS list, or zero if none was executed. TEST-COMMAND can, again, be any command that can exit with a success or failure status, and CONSEQUENT-COMMANDS can be any UNIX command, script or shell construct. As we already explained previously, the ";" may be replaced with one or more newlines wherever it appears. ExampleAn improved picturesort.sh script (see Section 9.2.2.2), which tests for available disk space. If not enough disk space is available, remove pictures from the previous months:
Note the initialization of the HOUR and DISKFULL variables and the use of options with ls and date in order to obtain a correct listing for TOREMOVE.
|
||
Home ![]() ![]() ![]() |