Bash Until Loop Statement – Syntax and Examples

Bash Until Loop

Bash Until Loop is a loop statement used to execute a block of statements repeatedly based on the boolean result of an expression. The block of statements are executed until the expression returns true. This might be little tricky. Let us understand this in much more detailed manner. When the expression evaluates to FALSE, the block of statements are executed iteratively. For the first time when the expression evaluates to TRUE, the loop is broken.

Syntax of Bash Until Loop

The syntax of until loop might look similar to that of bash while loop. But there is a difference in functionality

The expression can contain only one condition. If the expression should have multiple conditions, the syntax is as follows :

 

Example of bash until loop

Following is an until loop with only one condition in expression.

When the above until loop script is run in terminal,

 

Example of bash until loop

Following is an until loop with only multiple conditions in expression.

When the above until loop script is run in terminal,

 

To realize looping in bash, we have bash for loop and bash while loop along with until loop statement.

 

Conclusion :

In this Bash Tutorial – Bash Until Loop Statements, we have learnt about syntax of until loop statement in bash scripting for single and multiple conditions in expression with example scripts.