mercredi 25 janvier 2017

Check if parameter is value X or value Y

I want to check in my bash script, if a variable is equal to value 1 OR equal to value 2.

I don't want to use something like this, because the 'if true statements' are the same (some big echo texts), when the variable is equal to 1 or 2. I want to avoid data redundancy.

if [ $1 == 1 ] ; then echo number 1 ; else
if [ $1 == 2 ] ; then echo number 2 ; fi

More something like

if [ $1 == 1 OR 2 ] ; then echo number 1 or 2 ; fi

Aucun commentaire:

Enregistrer un commentaire