[ :shell 编程中的意外操作符 [英] [ :Unexpected operator in shell programming
本文介绍了[ :shell 编程中的意外操作符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码:
#!/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 脚本有什么错误吗?谢谢!
Is there any mistake in my bash script? Thanks!
推荐答案
bash 脚本没有错误.但是您正在使用 sh 执行它,它的语法不太广泛;)
There is no mistake in your bash script. But you are executing it with sh which has a less extensive syntax ;)
所以,改为运行 bash ./choose.sh
:)
So, run bash ./choose.sh
instead :)
这篇关于[ :shell 编程中的意外操作符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文