Bash IF语句不识别或表达式
我的头都快碎了。我不明白为什么下面的IF语句不起作用Bash IF语句不识别或表达式,bash,shell,unix,scripting,osx-lion,Bash,Shell,Unix,Scripting,Osx Lion,我的头都快碎了。我不明白为什么下面的IF语句不起作用 renameOption="-rs" if [[ $# -eq 4 ]]; then if [[ $renameOption != "-rs" ]] || [[ $renameOption != "-rb" ]]; then echo -e "\tArgument three needs to be '-rs' or '-rb'" echo -e "\tNow exiting script" exit fi flag=
renameOption="-rs"
if [[ $# -eq 4 ]]; then
if [[ $renameOption != "-rs" ]] || [[ $renameOption != "-rb" ]]; then
echo -e "\tArgument three needs to be '-rs' or '-rb'"
echo -e "\tNow exiting script"
exit
fi
flag=1
echo "Good to go"
fi
我知道语法是正确的,但我注意到系统无法识别第二个IF中的OR|
表达式。当使用单个表达式时,它可以正常工作,但我需要比较两个表达式,因此OR|
我正在运行OSX Lion 10.7.4,这有意义吗
$renameOption
始终不等于这两个选项中的任何一个。你可能想要&&
啊,门索,没错,我想我很沮丧,因为我的想法不对……我需要一个休息时间:)。。。感谢为了让您的错误消息有意义,您应该使用“&&”运算符,而不是“| |”,并将其放入“[[]]”块中,例如“[[a&&b]]”谢谢,有点困惑&
是正确的运算符