码迷,mamicode.com
首页 > 系统相关 > 详细

Shell循环语句:if

时间:2019-12-20 09:13:23      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:dev   off   else   bin   erro   超时   间隔   发送   使用   

[root@master1-192-168-117-18 ~]# vim mkcdrom.sh

#!/bin/bash
DIR="/media/cdrom"
if [ ! -e $DIR ]
then
mkdir -p $DIR
fi


[root@master1-192-168-117-18 ~]# vim chkhost.sh
#!/bin/bash

ping -c 3 -i 0.2 -W 3 $1 &> /dev/null
if [ $? -eq 0 ]
then
echo "Host $1 is on-line"
else
echo "Host $1 is off-line"
fi

[root@master1-192-168-117-18 ~]# bash chkhost.sh 192.168.1.11
Host 192.168.1.11 is on-line

注释:-c参数来规定尝试的次数,并使用-i参数定义每个数据包的发送间隔,以及使用-W参数定义等待超时时间


[root@master1-192-168-117-18 ~]# vim chkscore.sh
#!/bin/bash
read -p "Enter your score (0-100) :" GRADE
if [ $GRADE -gt 100 ];
then
echo "$GRADE is Error"
elif [ $GRADE -ge 85 ] && [ $GRADE -le 100 ];
then
echo "$GRADE is Excellent"
elif [ $GRADE -ge 70 ] && [ $GRADE -le 84 ];
then
echo "$GRADE is Pass"
else
echo "$GRADE is Fail"
fi
[root@master1-192-168-117-18 ~]# bash chkscore.sh
Enter your score (0-100) :200
200 is Error
[root@master1-192-168-117-18 ~]# bash chkscore.sh
Enter your score (0-100) :93
93 is Excellent
[root@master1-192-168-117-18 ~]# bash chkscore.sh
Enter your score (0-100) :80
80 is Pass
[root@master1-192-168-117-18 ~]# bash chkscore.sh
Enter your score (0-100) :23
23 is Fail

Shell循环语句:if

标签:dev   off   else   bin   erro   超时   间隔   发送   使用   

原文地址:https://blog.51cto.com/12400136/2460174

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!