ChrisAppStatic v0.4

Bash While Loops

What it does: Keeps running while a condition is true. Great for reading files line-by-line or polling commands until a state changes.

What is it? while repeats a block as long as a condition is true—great for reading files or polling a command.

Example: Read a file line by line

#!/bin/bash
FILE="names.txt"
while IFS= read -r line; do
  echo "Name: $line"
done < "$FILE"

← Back to home