Bash `loop` statements
for
loop
For loops allow repeated execution of a command sequence based on an iteration variable. Bash supports two kinds of for loop, a “list of values” and a “traditional” c-like method.
for varname in list
do
commands
done
Note that
- Bash
for
,in
,do
anddone
are keywords - list contains a list of items, which can be in the statement or fetched from a variable that contains several words separated by spaces.
- If list is missing from the for statement, then bash uses positional parameters that were passed into the shell.
Example 1:
Get hands-on with 1400+ tech skills courses.