我正在尝试将存储在字符串变量中的值与三个不同的可能值进行比较,如果其中任何一个值不匹配,则尝试使用逻辑运算符OR在单个if语句中抛出错误。但每次我都会出错,即使存储在变量中的值与可能的值之一相同。请找到我试过的片段。
if [[ "$TYPE" != "LOCAL" || "$TYPE" != "REMOTE" || "$TYPE" != "BOTH" ]]; then
echo -e "ntINCORRECT OR NULL ARGUMENTS PASSED. PLEASE VERIFY AND CORRECT THE USAGE MENTIONED AS BELOW: n"
Usage
exit 1
fi
if [[ "$TYPE" != "LOCAL" ]] || [["$TYPE" != "REMOTE" ]] || [["$TYPE" != "BOTH" ]]; then
echo -e "ntINCORRECT OR NULL ARGUMENTS PASSED. PLEASE VERIFY AND CORRECT THE USAGE MENTIONED AS BELOW: n"
Usage
exit 1
fi
我想您应该使用AND(&&(。参见:
或:
irb(main):002:0> true || true || false
=> true
irb(main):003:0> true || true || true
=> true
irb(main):004:0> false || false || false
=> false
和:
irb(main):005:0> true && true && false
=> false
irb(main):006:0> true && true && true
=> true
irb(main):007:0> false && false && false
=> false
使用ruby只是为了演示