zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    在source insight中阅读Python代码
    修改linux命令行提示符
    gcc链接程序时出现undefined reference to""错误
    [转]init.d解析
    [转]Linux中find常见用法示例
    Linux的网卡由eth0变成了eth1,如何修复?
    测试使用Windows Live Writer
    黑盒测试
    白盒测试技术(二)
    白盒测试技术(一)
  • 原文地址:https://www.cnblogs.com/xiongjiawei/p/7367664.html
Copyright © 2011-2022 走看看