Artificial intelligent assistant

Using the not equal operator for string comparison I tried to check if the `PHONE_TYPE` variable contains one of three valid values. if [ "$PHONE_TYPE" != "NORTEL" ] || [ "$PHONE_TYPE" != "NEC" ] || [ "$PHONE_TYPE" != "CISCO" ] then echo "Phone type must be nortel,cisco or nec" exit fi The above code did not work for me, so I tried this instead: if [ "$PHONE_TYPE" == "NORTEL" ] || [ "$PHONE_TYPE" == "NEC" ] || [ "$PHONE_TYPE" == "CISCO" ] then : # do nothing else echo "Phone type must be nortel,cisco or nec" exit fi Are there cleaner ways for this type of task?

I guess you're looking for:


if [ "$PHONE_TYPE" != "NORTEL" ] && [ "$PHONE_TYPE" != "NEC" ] &&
[ "$PHONE_TYPE" != "CISCO" ]


The rules for these equivalents are called De Morgan's laws and in your case meant:


not(A || B || C) => not(A) && not(B) && not (C)


Note the change in the boolean operator or and and.

Whereas you tried to do:


not(A || B || C) => not(A) || not(B) || not(C)


Which obviously doesn't work.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2c83415cc96ea2c4509092a7e787f46c