小编典典

[:shell编程中的意外运算符

all

我的代码:

    #!/bin/sh
    #filename:choose.sh
    read choose
    [ "$choose" == "y" -o "$choose" == "Y" ] && echo "Yes" && exit 0
    [ "$choose" == "n" -o "$choose" == "N" ] && echo "No"  && exit 0
    echo "Wrong Input" && exit 0

但是当我执行

    sh ./choose.sh

终端提示我

   [: 4: n: :Unexpected operator
   [: 5: n: :Unexpected operator

我的 bash 脚本有什么错误吗?谢谢!


阅读 69

收藏
2022-05-30

共1个答案

小编典典

您的bash 脚本没有错误。但是您正在使用语法较少的 sh执行它;)

所以,bash ./choose.sh改为运行:)

2022-05-30