Bash OR 运算符不评估多个变量

eek*_*nky 0 bash

我的 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_NAMEcrowd.server.com 我需要它在移动之前评估所有的变量

Dmi*_*yev 7

这是可以预料的。当||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)