keyword

Bash for loop

Iterates once per expanded word, or positional argument when in is omitted. Returns the last executed command status or zero if no iteration runs.

Formal Syntax & Structure

bash syntaxbash
for name [in words ...]; do commands; done

Parameters & Attributes

NameTypeDescription
nameidentifierLoop variable.
wordsword listExpanded items; omitted uses positional arguments.

Return Value

exit status

Iterates once per expanded word, or positional argument when in is omitted. Returns the last executed command status or zero if no iteration runs.

Working Example

Example Snippetbash
for item in 'daily report' '' backup; do  printf '[%s]\n' "$item"done
Bash Reference