Skip to content

Bash For Loops

A for loop repeats a block of commands for a known range or list. Useful for automation.

Example

#!/bin/bash
for i in {20..0}
do
  echo "Countdown: $i"
  sleep 1
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 →