while, until & select in Bash

From the Bash Scripting cheat sheet · Loops · verified Jul 2026

while, until & select

Condition-driven loops and reading input.

bash
# Quick Reference
while [[ $n -lt 5 ]]; do (( n++ )); done
until [[ -f ready ]]; do sleep 1; done
while read -r line; do echo "$line"; done < file
💡 while IFS= read -r line; do ... done < file is THE safe way to read lines.
⚡ IFS= prevents trimming whitespace; -r stops backslash mangling in read.
📌 until is while's inverse - it loops until the condition succeeds.
🟢 break leaves the loop entirely; continue jumps to the next iteration.
loopswhileread

Continue with Bash Scripting

Save the full cheat sheet or work through every related task.

More Bash tasks

Back to the full Bash Scripting cheat sheet