有时候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

 

 

将能解决错误

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-13
  • 2021-05-06
  • 2021-12-09
  • 2021-06-20
  • 2021-07-28
  • 2021-10-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2021-12-30
  • 2022-12-23
相关资源
相似解决方案