how to make several comparisons in the bash by placing the condition and comparison points next to instead of the long queue ?
that something like this
before :
JavaScript
x
if [[ $var == "aaa" || $var == "bbb" || $var == "ccc" || $var == "ddd" ]];
then
echo "good";
fi
after (what I want):
JavaScript
if [[ $var==["aaa","bbb","ccc","ddd"] ]];
then
echo "good";
fi
Advertisement
Answer
Try this using bash regex with the keywork =~
:
JavaScript
if [[ $var =~ ^(aaa|bbb|ccc|ddd)$ ]];
then
echo "good";
fi
Edit :
As seen in comments, for real you need to compare int
, not strings
, so :
JavaScript
((var%3 == 0)) && echo "ok"
Using bash arithmetic