Conditional and Looping Statements

if

if test-commands; then
  consequent-commands;
[elif more-test-commands; then
  more-consequents;]
[else alternate-consequents;]
fi

case

case word in
    [ [(] pattern [| pattern]...) command-list ;;]...
esac
  • case will selectively execute the command-list corresponding to the first pattern that matches word.

select

select name [in words ...]; do commands; done
  • Expand the list of words follwiong in, generating a list of items to stderr preceeded by a number. A line is read from stdin, and the corresponding

until

until test-commands; do consequent-commands; done

while

while test-commands; do consequent-commands; done

for

for name [ [in words ...] ; ] do commands; done
  • expand words and then execute commands once for each
  • if in words is not specified, the for command executes once forr each positional parameter.
for (( expr1 ; expr2 ; expr3 )) [;] do commands ; done