if;脚本中退出语句:exit 数字,用$?查时为exit设置的数字,此数字为程序执行完后的返回数据,可以通过此方法自动设定...

if [ 条件 ];then

  代码

fi

if [ 条件 ]

  then

    代码

fi

[root@localhost ~]# df
文件系统          1K-块    已用     可用 已用% 挂载点
/dev/sda5      16558080 1443696 15114384    9% /
devtmpfs         490168       0   490168    0% /dev
tmpfs            499968       0   499968    0% /dev/shm
tmpfs            499968    6872   493096    2% /run
tmpfs            499968       0   499968    0% /sys/fs/cgroup
/dev/sdb1        999320    2564   927944    1% /disk1
/dev/sdb5       1998672    6144  1871288    1% /disk5
/dev/sda2       2086912   33160  2053752    2% /home
/dev/sda1        201380  116576    84804   58% /boot
tmpfs             99996       0    99996    0% /run/user/0
[root@localhost ~]# df|grep sda5
/dev/sda5      16558080 1443696 15114384    9% /
[root@localhost ~]# df|grep sda5|awk '{print $5}'
9%
[root@localhost ~]# df|grep sda5|awk '{print $5}'|cut -d % -f1
9
[root@localhost ~]# ls
shFiles  testfile  testfileb
[root@localhost ~]# vim myShell.sh  注释:以下为shell脚本代码
#!/bin/bash

#统计根分区使用率

rate=$(df|grep /dev/sda5|awk '{print $5}'|cut -d % -f1)

if [ $rate -ge 80 ];then  注释:[ $rate -ge 80 ]可写成test $rate -ge 80
        echo "/dev/sda5 is full!"
fi

 if [ 条件 ]

  then

    执行语句

  else

    执行语句

fi

 

if [ 条件 ]

  then

    执行语句

elif [ 条件 ]

  then

    执行语句

...

elif  [ 条件 ]

  then

    执行语句

  else

    执行语句

fi

转载于:https://www.cnblogs.com/xiongjiawei/p/7367664.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值