zoukankan      html  css  js  c++  java
  • shell运行报 too many arguments错误

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

     

     

    将能解决错误

  • 相关阅读:
    系统测试的策略
    POJ1611(并查集)
    POJ2752(KMP)
    POJ3176(DP)
    HDU2579(BFS)
    HDOJ1175(BFS)
    HDOJ1242(BFS)
    HDOJ1180(BFS)
    HDOJ1372(BFS)
    HDOJ2717(BFS)
  • 原文地址:https://www.cnblogs.com/Cherie/p/3200292.html
Copyright © 2011-2022 走看看