[shell]shell中if语句的使用
Posted aaronGao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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
执行结果:
[[email protected] if]# ./grade.sh Please input your grade: You don‘t input your grade.... [[email protected] if]# ./grade.sh Please input your grade:53 Right,Your grade is F. [[email protected] if]# ./grade.sh Please input your grade:88 Good,Your grade is B.
总结:条件判断在shell语句中经常用到,需要熟练掌握,在此基础上才能练就一手很好的脚本编写能力。祝各位每天都能获得很大的进步.....
以上是关于[shell]shell中if语句的使用的主要内容,如果未能解决你的问题,请参考以下文章