首页 > 代码库 > [shell]shell中if语句的使用
[shell]shell中if语句的使用
转自: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语句中经常用到,需要熟练掌握,在此基础上才能练就一手很好的脚本编写能力。祝各位每天都能获得很大的进步.....
[shell]shell中if语句的使用
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。