C-Style Loops in Bash
Use arithmetic for loops with counters and step values.
Write for ((i=1;i<=5;i++)) to loop five times with a counter.
01Command
Command
$ for ((i=1;i<=5;i++)); do echo "step $i"; done02What it does
The C-style for loop gives scripts an explicit counter without seq or external tools, and supports any arithmetic expression such as i+=2. It is the clearest way to retry an operation or iterate over a numeric range.
03Risk
!Warning: Bash arithmetic is integer-only; use bc or awk for floating-point counters.
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- bash.1.en.html manual pageEvidence: The bash manual page documents arithmetic for loops.
Last verified: 2026-10-13 · Category: Developer