Loops and Lists
While Loops
Repeating Until Done
A while loop repeats as long as its test succeeds. Updating the loop variable moves the script toward the exit.
Program
Play the script to watch count decrease until the loop finishes.
while_loop.sh
#!/usr/bin/env bash
count=3
while (( count > 0 )); do
echo "tick:$count"
count=$((count - 1))
done
echo "done"
while loop
`while` checks its condition before each iteration.
loop exit
The loop stops once the condition command returns a nonzero status.