[ :Unexpected operator in shell programming [dupli

2020-01-24 06:32发布

My code:

    #!/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

But when I execute

    sh ./choose.sh

terminal prompt me that

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

Is there any mistake in my bash script? Thanks!

标签: linux bash shell
7条回答
再贱就再见
2楼-- · 2020-01-24 07:02

To execute it with Bash, use #!/bin/bash and chmod it to be executable, then use

./choose.sh
查看更多
登录 后发表回答