简单shell脚本:判断成绩等级[root@server ~]# vim
#!/bin/bash
echo "Please enter a number"
read num
if [ -z $num ]                  #判断是否输⼊了数字
then
echo "you enter nothing,please enter a number"
read num
else
if [ $num -lt 0 -o $num -gt 100 ]    #判断数据是否合法
echo "The number is invalid,please enter a number"
read num
else
if [ $num -ge 90 ]    #⼤于等于90,成绩等级为A
then
echo "The grade is A"
else
if [ $num -ge 80 ]    #⼤于等于80,成绩等级为B
then
echo "The grade is B"shell最简单脚本
else
if [ $num -ge 70 ]    #⼤于等于70,等级等级为C
then
echo "The grade is C"
else
if [ $num -ge 60 ]    #⼤于等于60,成绩等级为D
then
echo "The grade is D"
else
echo "The grade is E"    #⼩于60,成绩等级为E
fi
fi
fi
fi
fi
fi
————————————————————
以上为脚本内容
[root@server ~]# chmod u+x test.sh  #给脚本可执⾏权限
执⾏脚本结果:
[root@server ~]# ./test.sh
Please enter a number
45
The grade is E
[root@server ~]# ./test.sh
Please enter a number
77
The grade is C
[root@server ~]# ./test.sh
Please enter a number
89
The grade is B
[root@server ~]# ./test.sh
Please enter a number
90
The grade is A

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。