Sem 3‎ > ‎OS (Unix) LAB‎ > ‎

D8: switch case

posted Oct 9, 2011, 6:56 AM by Neil Mathew   [ updated Oct 9, 2011, 6:56 AM ]
It is a control statement used for decision making.


Syntax:

case $<variable> in

<option1>)
<statement>
;;

<option2>)
<statement>
;;

esac


Example: 

case $ch in

+)
res=`expr $a + $b`
echo "Sum is: $res"
;;

-)
res=`expr $a - $b`
echo "Remainder is: $res"
;;


*)
res=`expr $a \* $b`
echo "Product is: $res"
;;

/)
res=`expr $a / $b`
echo "Quotient is: $res"
;;

esac


Comments