我的代码:
#!/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脚本有什么错误吗?谢谢!
您的 bash 脚本没有任何错误。但是您正在使用 sh 来执行它, sh的 语法不太广泛;)
因此,bash ./choose.sh改为运行:)
bash ./choose.sh