lundi 29 mai 2017

Writing a better IF condition

I need help writing a better code for the following logic:

if [[ "$CONDITION1" == "BAD" && "$PERCENT1" -ge 10 && "$PERCENT1" -le 30 ]] || [[ "$CONDITION1" == "GOOD" && "$PERCENT1" -ge 30 && "$PERCENT1" -le 60 ]] || [[ "$CONDITION2" == "BAD" && "$PERCENT2" -ge 10 && "$PERCENT2" -le 30 ]] || [[ "$CONDITION2" == "GOOD" && "$PERCENT2" -ge 30 && "$PERCENT2" -le 60 ]];
then
        echo "RESULT 1"
elif [[ "$CONDITION1" == "BAD" && "$PERCENT1" -gt 30 ]] || [[ "$CONDITION1" == "GOOD" && "$PERCENT1" -gt 60 && "$PERCENT1" -le 100 ]] || [[ "$CONDITION2" == "BAD" && "$PERCENT2" -gt 30 ]] || [[ "$CONDITION2" == "GOOD" && "$PERCENT2" -gt 60 && "$PERCENT2" -le 100 ]];
then
        echo "RESULT 2"
else
        echo "RESULT 3"
fi

This is the basis for the conditions:

RESULT 1: PERCENT1 is 10-30% if CONDITION1=BAD

OR PERCENT1 is 30-60% if CONDITION1=GOOD

RESULT 2: PERCENT1>30% if CONDITION1=BAD

OR PERCENT1 is 60-100% if CONDITION1=GOOD

Aucun commentaire:

Enregistrer un commentaire