next up previous contents
Next: The while command Up: C Shell Programming Previous: The if command   Contents

The case command

The sh program:-

 
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."

becomes the csh program:-

 
echo -n "Enter the name of an animal: "
set ANIMAL = $<
echo -n "The $ANIMAL has "
switch ( $ANIMAL )
case horse:
case dog:
case cat:
             echo -n "four"
             breaksw
case man:
case kangaroo:
             echo -n "two"
             breaksw
default:
        echo -n "an unknown number of"
endsw
echo " legs."



P.D. Gronbech (IT Staff) 2015-10-02