dimanche 18 octobre 2020

Shorter multiple if statement in bash/shell [duplicate]

Is there anyway to "simplify" or make a long if statement line easier for adding/removing conditions?

for example (but a lot more of conditions):

if [[ "$a1"=="test1" ]] || [[ "$a1"=="cat4" ]] || [[ "$a1"=="dog7" ]] || [[ "$a1"=="car5" ]] || [[ "$a1"=="mouse" ]] || [[ "$a1"=="alien" ]]; then....

and instead do some kind of array with the values or something and call it like;

if [[ "$a1"=="items[]" ]]; then..

is this even possible?

Aucun commentaire:

Enregistrer un commentaire