The for Loop
The “for” loop is designed to execute a set of commands on a series of items, one item after the other. The items can be:
- From a hard coded list
- Stored in a variable
- From a list generated by the command line
- Listed from a file
- Passed as command line arguments
This is different from the count controlled “for” loop defined by some programming languages.
for Loop Syntax

Key points
- The commands between “do” and “done” will be executed for each item after the “in”.
- The command(s) are referred to as the body of the loop.
- A for loop can be generated from the command line, but is most often part of a script file.
for Loop Examples