一尘不染

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

linux

我的代码:

    #!/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脚本有什么错误吗?谢谢!


阅读 408

收藏
2020-06-02

共1个答案

一尘不染

您的 bash 脚本没有任何错误。但是您正在使用 sh 来执行它, sh的 语法不太广泛;)

因此,bash ./choose.sh改为运行:)

2020-06-02