我正在编写一个脚本,用于检查 3 个不同的变量并在 true 上匹配。但是,我只需要它仅在所有条件匹配时才返回 true。现在,如果我的运算符列表中只有一个或两个条件匹配,则返回 true。
if [ -z "$VAR3" ] || [ "$VAR1" -ge 10 ] || [ "$VAR2" != "WORKING" ]; then
echo "app failed "$VAR1" check-ins"
exit 2
elif [ -n "$VAR3" ] || [ "$VAR1" -le 10 ] || [ "$VAR2" == "WORKING" ]; then
echo "$VAR3" pid active connection is "$VAR2"
exit 0
fi
我应该只用 &&&??
是的
,||
表示OR
逻辑运算符,如果至少有一个运算符true
,它将返回true
。 &&
表示AND
逻辑运算符,则返回当且仅当所有运算符都true
true
if [ -z "$VAR3" ] && [ "$VAR1" -ge 10 ] && [ "$VAR2" != "WORKING" ]; then
echo "app failed "$VAR1" check-ins"
exit 2
elif [ -n "$VAR3" ] && [ "$VAR1" -le 10 ] && [ "$VAR2" == "WORKING" ]; then
echo "$VAR3" pid active connection is "$VAR2"
exit 0
fi