有时候shell在运行的时候可能会报 too many arguments错误,出现这种错误的一般情况是出现了多值问题,也就是一个变量可能有多个值了。
例:#!/bin/sh
echo "Is it morning? Please answer yes or no "
read timeofday
if [ $timeofday = "yes" ]; then
echo "Good morning"
elif [ $timeofday = "no" ];then
echo "Good afternoon"
else
echo "Sorry,$timeofday not recognized. Enter yes or no "
exit 1//异常退出
fi
exit 0
该例中就会报错 exit: too many arguments。表示exit有多个值。如果该为:
#!/bin/sh
echo "Is it morning? Please answer yes or no "
read timeofday
if [ $timeofday = "yes" ]; then
echo "Good morning"
exit 0
elif [ $timeofday = "no" ];then
echo "Good afternoon"
exit 0
else
echo "Sorry,$timeofday not recognized. Enter yes or no "
exit 1//异常退出
fi
将能解决错误