#!/bin/bash
echo "Please input a integer(0-100):"
read score
if [ "$score" -lt 0 -o "$score" -gt 100 ];then
echo "The score what you input is not integer or the score is not in(0-100)"
else
if [ "$score" -ge 90 ];then
echo "The grade is A!"
else
if [ "$score" -ge 80 ];then
echo "The grade is B!"
else
if [ "$score" -ge 70 ];then
echo "The grade is C!"
else
if [ "$score" -ge 60 ];then
echo "The grade is D!"
else
echo "The grade is E!"
fi
fi
fi
fi
fi
结果:
~/Note/test # ./2if_else.sh
Please input a integer(0-100):
80
The grade is B!
~/Note/test # ./2if_else.sh
Please input a integer(0-100):
20
The grade is E!
~/Note/test # ./2if_else.sh
Please input a integer(0-100):
90
The grade is A!
~/Note/test # ./2if_else.sh
Please input a integer(0-100):
70
The grade is C