Skip to content

Bash While Loops

while repeats while a condition is true. Great for reading files or polling.

Example

#!/bin/bash
i=5
while (( i >= 0 )); do
  echo "$i"
  ((i--))
done

How to run it

  1. Save it to a file.
  2. Run chmod +x filename.sh where applicable.
  3. Run it from the terminal.

← Back homeRun in Sandbox →