Control
Control statements, Chapters 27, 29 and 31.
  1. If statement
    if command ; then commands elif command ; then commands ... else commands fi
    1. The test is a command. It is true if it exits normally, false otherwise.
    2. Often used to test if a command succeeded.
    3. There is also a test command designed just to run tests.
      1. Called test or [
      2. Compare for string equality. if [ $resp = "yes" ]; then
      3. Numerical comparisons if [ $a lt $b ]; then
      4. File tests. if [ -r "config.txt" ]; then
    4. Commands can include one or more commands, separated by line breaks or semicolons.
  2. While loop
    while command ; do commands done
    1. Test is by exit status same as if.
    2. Repeats while true as in regular PLs.
  3. For-each loop
    for var in list of strings; do commands done
    1. Executes the commands once for each member of the list.
    2. Sets var equal to the list value.
    3. The list is often either a file wild card or the argumnet list $*.
  4. Case statement
    case word in pattern) commands ;; pattern) commands ;; ... esac
    1. Runs the first set of commands that matches.
    2. Patterns are the same as file name wildcards.
    3. A pattern may also consist of several wildcard expressions separated by the | character. Matches if any do.
    4. Patterns are often a list of specific items followed by a * as a default.