[oracle@jhoa 6]$ cat elif.sh
var="$1"
if [ $var = "01" ]
then
echo "Jan"
elif [ $var = "02" ]
then
echo "Feb"
elif [ $var = "03" ]
then
echo "Mar"
elif [ $var = "04" ]
then
echo "Apr"
fi
[oracle@jhoa 6]$ sh elif.sh 02
Feb
改为case 语句:
[oracle@jhoa 6]$ cat case.sh
var="$1"
case $var in
01)
echo "Jan"
;;
02)
echo "Feb"
;;
03)
echo "Mar"
;;
04)
echo "Apr"
;;
esac
[oracle@jhoa 6]$ sh ./case.sh 04
Apr