我的 bash 脚本中的以下行无法评估多个 OR 运算符。这是检查第一个然后继续
if [[ "${SERVER_NAME}" != $BITBUCKET || $CONFLUENCE || $CROWD || $JIRA || $JENKINS ]]; then
other code here...
fi
Run Code Online (Sandbox Code Playgroud)
与bash -x
对剧本我得到这样的;
+ [[ crowd.server.com != code.server.com ]]
Run Code Online (Sandbox Code Playgroud)
这是$BITBUCKET
可变的,$SERVER_NAME
是crowd.server.com
我需要它在移动之前评估所有的变量
这是可以预料的。当||
operator 的一项 评估为 时true
,整个序列的值变为true
。
尝试使用&&
运算符,并根据要比较的字符串多次使用字符串比较运算符。
更好的是,使用case
语句:
case "${SERVER_NAME}" in
"$BITBUCKET" | "$CONFLUENCE" | "$CROWD" | "$JIRA" | "$JENKINS") ;; # do nothing for these servers
*)
# your original code here...
;;
esac
Run Code Online (Sandbox Code Playgroud)