samedi 29 septembre 2018

Check if variable is a number below 10 or the text "QUIT"

I would to stay in this loop as long as $CHOICE is not "QUIT" or a number below 10.

I'm using this :

CHOICE=0
while [ "$CHOICE" -gt "10" ] && [ "$CHOICE" != "QUIT" ]; do
  read CHOICE < /dev/tty
done

But if I put let's say "test", the script crashes because it is expecting an integer in the first test.

What can I do to avoid this crash ?

Aucun commentaire:

Enregistrer un commentaire