http://www.usf.uos.de/infoservice/doc/

(features.info)Conditional Constructs


Next: Shell Functions Prev: Looping Constructs Up: Bourne Shell Features
Enter node , (file) or (file)node

Conditional Constructs
======================

`if'
     The syntax of the `if' command is:

          if TEST-COMMANDS; then
            CONSEQUENT-COMMANDS;
          [elif MORE-TEST-COMMANDS; then
            MORE-CONSEQUENTS;]
          [else ALTERNATE-CONSEQUENTS;]
          fi

     Execute CONSEQUENT-COMMANDS only if the final command in
     TEST-COMMANDS has an exit status of zero.  Otherwise, each `elif'
     list is executed in turn, and if its exit status is zero, the
     corresponding MORE-CONSEQUENTS is executed and the command
     completes.  If "`else ALTERNATE-CONSEQUENTS'" is present, and the
     final command in the final `if' or `elif' clause has a non-zero
     exit status, then execute ALTERNATE-CONSEQUENTS.

`case'
     The syntax of the `case' command is:

          `case WORD in [PATTERN [| PATTERN]...) COMMANDS ;;]... esac'

     Selectively execute COMMANDS based upon WORD matching PATTERN.
     The ``|'' is used to separate multiple patterns.

     Here is an example using `case' in a script that could be used to
     describe an interesting feature of an animal:

          echo -n "Enter the name of an animal: "
          read ANIMAL
          echo -n "The $ANIMAL has "
          case $ANIMAL in
            horse | dog | cat) echo -n "four";;
            man | kangaroo ) echo -n "two";;
            *) echo -n "an unknown number of";;
          esac
          echo "legs."


Next: Shell Functions Prev: Looping Constructs Up: Bourne Shell Features
[ Dokumentation lokal installierter Software ]