/ Linux Reviews / Beginners: Learn Linux / Bash Guide for Beginners - en


9.3. The until loop

9.3.1. What is it?

The 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.

9.3.2. Example

An improved picturesort.sh script (see ), which tests for available disk space. If not enough disk space is available, remove pictures from the previous months:

Figure 9-2. More nested while loops - safesort.sh

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.


/ Linux Reviews / Beginners: Learn Linux / Bash Guide for Beginners


Meet new people

Adult Dating