samedi 28 septembre 2019

How can I combine these && if conditions in bash?

I want to write a bash script that takes in marks of 5 subjects and the marks cannot be greater than 100. How can I avoid typing -le 100 each time.

 while true
do
echo "enter marks of 5 subjects"
read m1 m2 m3 m4 m5
if [ $m1 -le 100 ] && [ $m2 -le 100 ] && [ $m3 -le 100 ] && [ $m4 -le 100 ] && [ $m5 -le 100 ]
then
        break
else
 echo "marks cannot be more than 100"
fi
done

Aucun commentaire:

Enregistrer un commentaire