[Next] [Previous] [Up] [Top] [Contents]

9.9.2 Conditional switch and case

9.9.2.2 Csh

switch (parameter)

case pattern1:

command list1

[breaksw]

case pattern2:

command list2

[breaksw]

default:

command list for default behavior

[breaksw]

endsw

breaksw is optional and can be used to break out of the switch after a match to the string value of the parameter is made. Switch doesn't accept "|" in the pattern list, but it will allow you to string several case statements together to provide a similar result. The following C shell script has the same behavior as the Bourne shell case example above.

#!/bin/csh -f

switch ($1)

case aa:

case ab:

echo A

breaksw

case b?:

echo -n "B "

echo $1

breaksw

case c*:

echo C

breaksw

default:

echo D

endsw


Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]