keyword

Bash while loop

Repeats while condition commands return zero; condition is checked first. Returns the last body command status or zero if no body runs.

Formal Syntax & Structure

bash syntaxbash
while test-commands; do commands; done

Return Value

exit status

Repeats while condition commands return zero; condition is checked first. Returns the last body command status or zero if no body runs.

Working Example

Example Snippetbash
n=1while (( n <= 3 )); do  printf '%s\n' "$n"  n=$(( n + 1 ))done
Bash Reference