Table of Contents

BASH - Loops While loop

A while loop is used for running some instruction multiple times:


Format

while [ condition ]
do
commands 1
commands n
done

NOTE: The space surrounding the square brackets is mandatory.


Example

#!/bin/bash
i=0
 
while [ $i -le 2 ]
do
echo Number: $i
((i++))
done