lundi 27 juin 2016

Check all IF conditions before moving forward. (Multiple If Conditions, BASH)

This is what I have. I'm forced to use a consequent command is there is a match. I want to avoid that if possible.

if [[ ${USER} == "user1" || "user2" || "user3" || "user4" ]]; then
     echo "user matches."
else
     echo "${USER} Does not match configured users."
     exit 1
fi

Is there a way to flip the syntax to exit on the subsequent command? That would look cleaner and reduce the line count. The problem here is, it will exit on the first true condition. So maybe a way to check all conditions before moving forward?

if [[ ${USER} != "user1" || "user2" || "user3" || "user4" ]]; then
     echo "${USER} Does not match configured users."
     exit 1
fi

Aucun commentaire:

Enregistrer un commentaire