I know that the =~
operator can be used to identify that a string is in a list...
if [[ "$var" =~ ^(str1|str2|str3)$ ]]
then
echo "$var is in the list"
else
echo "$var is not in the list"
fi
...but this syntax is not efficient if I am only interested in the else
:
if [[ "$var" =~ ^(str1|str2|str3)$ ]]
then
echo "foo" >/dev/null #bogus anything to avoid empty "then" clause
else
my_awesome_function_here
fi
I know that if I was just checking against a single string, the !=
operator could be used...
if [[ "$var" != "str1" ]]; then
my_awesome_function
fi
...but !=~
is not a valid operator.
Is there an equivalent to !=~
? Is there something else I'm missing?