|
我在入门教程里搜索了switch的用法.写了下面的程序.
#! /bin/bash
if [ $# -ne 2 ]
then
echo You must input the month and years
else
switch ($1)
case "January":
cal 1 $2
case "February":
cal 2 $2
case "March":
cal 3 $2
case "April":
cal 4 $2
case "May":
cal 5 $2
case "June":
cal 6 $2
case "July":
cal 7 $2
case "August":
cal 8 $2
case "September":
cal 9 $2
"mycal" 33L, 478C written
[st1866@localhost st1866]$ mycal May 2002
/home/st18xx/st1866/mycal: line 6: syntax error near unexpected token
/home/st18xx/st1866/mycal: line 6: `switch ($1)'
[st1866@localhost st1866]$ cat mycal
#! /bin/bash
if [ $# -ne 2 ]
then
echo You must input the month and years
else
switch ($1)
case "January":
cal 1 $2
case "February":
cal 2 $2
case "March":
cal 3 $2
case "April":
cal 4 $2
case "May":
cal 5 $2
case "June":
cal 6 $2
case "July":
cal 7 $2
case "August":
cal 8 $2
case "September":
cal 9 $2
case "October":
cal 10 $2
case "November":
cal 11 $2
case "December":
cal 12 $2
default:
echo "lease input right month!
fi
为什么运行后会出现:
/home/st18xx/st1866/mycal: line 6: syntax error near unexpected token
/home/st18xx/st1866/mycal: line 6: `switch ($1)' |
|