标签:color flow file .com pre this 整数 let overflow
转自:http://lovelace.blog.51cto.com/1028430/1211353
if 判断条件;then statement1 statement2 ....... fi
if 判断条件;then statement1 statement2 ..... else statement3 statement4 fi
[ ! "$name" ] [ -z "$name" ]
if [ $x -gt 90 -o $x -lt 100 ] case $x in 100) 9[0-9])
if [ "X$name" != "x" ]
#/bin/bash #Verson:0.1 #Auther:lovelace #Pragram:This pragram is calculation your grade #import an argument read -p "Please input your grade:" x declare -i x #jugemet $x value is none or not if [ "$x" == "" ];then echo "You don‘t input your grade...." exit 5 fi #jugement the gread level if [[ "$x" -ge "90" && "$x" -le "100" ]];then echo "Congratulation,Your grade is A." elif [[ "$x" -ge "80" && "$x" -le "89" ]];then echo "Good,Your grade is B." elif [[ "$x" -ge "70" && "$x" -le "79" ]];then echo "Ok.Your grade is C." elif [[ "$x" -ge "60" && "$x" -le "69" ]];then echo "Yeah,Your grade is D." elif [[ "$x" -lt "60" ]];then echo "Right,Your grade is F." else echo "Unknow argument...." fi
执行结果:
[root@lovelace if]# ./grade.sh Please input your grade: You don‘t input your grade.... [root@lovelace if]# ./grade.sh Please input your grade:53 Right,Your grade is F. [root@lovelace if]# ./grade.sh Please input your grade:88 Good,Your grade is B.
总结:条件判断在shell语句中经常用到,需要熟练掌握,在此基础上才能练就一手很好的脚本编写能力。祝各位每天都能获得很大的进步.....
标签:color flow file .com pre this 整数 let overflow
原文地址:http://www.cnblogs.com/aaronLinux/p/7074725.html