我的代码:
#!/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执行它;)
所以,bash ./choose.sh改为运行:)
bash ./choose.sh