Chapter 8: Loops

for Loop

There are 2 variations of for loop in Bash:

Below is a type of for loop which is characterized by counting. The range is specified by a beginning and end:

1 for user in $*; do
2 	echo $user
3 done

A second variation involves a three-parameter loop control expression; consisting of an initializer (EXP1), a loop-test or condition (EXP2), and a counting expression/step (EXP3).

1 for (( INITIALIZER;CONDITION;STEP ))
2 do
3 	commands
4 done

while Loop

1 while [ "$password" != "$password_check" ]; do
2 	echo "Passwords do not match"
3 done