• shell(2)-&& 与 || 逻辑或与非



    test 命令测试

    -常见的测试类型
    –测试文件状态
    –字符串比较
    –整数值比较
    –逻辑测试
    && 如果是“前面”(真),则“后面”
    [ -f /var/run/dhcpd.pid ] && rm /var/run/dhcpd.pid 检查 文件是否存在,如果存在就删掉
    [ -d /media/cdrom ] && echo "yes"

    || 如果不是“前面”(假),则“后面”
    [ -f /usr/sbin/dhcpd ] || exit 0 检验文件是否存在,如果存在就退出
    [ -f /media/cdrom ] || echo "no"
    -------------------------------------------------------------------------
    cat /proc/meminfo #查看额定内存数量,到达额定数量系统才会swap
    -------------------------------------------------------------------------

    比较磁盘大小
    DISKSIZE=`df -lh | grep sda2 | awk '{print $4}' | awk -F "G" '{print $1}'`
    [ $DISKSIZE -lt 100 ] && echo ${DISKSIZE}MB
    [root@localhost ~]# BootUsage=`df -hT | grep "/boot" | awk '{print $6}' | cut -d "%" -f 1`
    [root@localhost ~]# echo $BootUsage
    12
    [root@localhost ~]# [ $BootUsage -gt 95 ] && echo "YES"
    -------------------------------------------------------------------------
    [root@localhost ~]# echo $USER
    root
    [root@localhost ~]# [ $USER != "teacher" ] && echo "Not teacher"
    Not teacher
    [root@localhost ~]# [ $USER = "teacher" ] || echo "Not teacher"
    Not teacher
    [root@localhost ~]# [! $USER = "teacher" ] || echo "Not teacher"
    -------------------------------------------------------------------------

  • 相关阅读:
    眼过千遍不如手过一遍!
    等老了,做一个视频编辑
    不建议用wxWidgets,底层有过多的bug
    MFC新婚之夜(笑昏,大概是指MFC的人固步自封)
    Twitter算法
    Ruby on rails3
    重提基数排序
    Hashtable Dictionary List
    try { var mergeFilePath = string.Format("{0}mergepdf.pdf", tempDownDir); PDFPrintHelper.MergePDFFile(pdfList, mergeFi
    查找树
  • 原文地址:https://www.cnblogs.com/luoyan01/p/9734079.html
Copyright © 2020-2023  润新知