Bash While Loop Statement – Syntax and Examples

Bash While Loop

Bash While Loop is a loop statement used to execute a block of statements repeatedly based on the boolean result of an expression, for as long as the expression evaluates to TRUE.

Syntax of Bash While Loop

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

Example of bash while loop

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

When the above while loop script is run in terminal,


Example of while loop – multiple conditions in expression

Run the above while loop script in terminal,

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


Conclusion :

In this Bash TutorialBash While Loop, we have learnt about syntax of while loop statement in bash scripting for single and multiple conditions in expression with example scripts.