我已将 NODE_ENV 设置为测试。我无法弄清楚原因,但由于某种原因,这个IF语句总是返回true(即使我设置了NODE_ENV =测试)。
if [[ $NODE_ENV != "testing" || $NODE_ENV != "development" ]]; then
echo "❌ Not a development OR testing environment: NODE_ENV is not set to development OR testing"
exit 1
fi
怎么会发生这种情况?
我也尝试格式化if [] || [];
之类的if语句,但也没有。
答案 0 :(得分:1)
你想要的逻辑在这里使用AND,而不是OR:
if [[ $NODE_ENV != "testing" && $NODE_ENV != "development" ]]; then
echo "❌ Not a development OR testing environment: NODE_ENV is not set to development OR testing"
exit 1
fi
与之相反:
$NODE_ENV == "testing" || $NODE_ENV == "development"
是:
$NODE_ENV != "testing" && $NODE_ENV != "development"