zoukankan      html  css  js  c++  java
  • linux系统中逻辑测试语句

    1、&& 表示与,上一句执行成功则执行下一句;|| 表示或,上一句执行失败则执行下一句

    [root@linuxprobe test]# touch a.txt
    [root@linuxprobe test]# ls
    a.txt
    [root@linuxprobe test]# [ -e a.txt ] && mkdir test  ## a.txr存在,&&连接则会执行下一句
    [root@linuxprobe test]# ls
    a.txt  test
    [root@linuxprobe test]# [ -e b.txt ] && mkdir test2  ## b.txt不存在,&&连接不执行下一句
    [root@linuxprobe test]# ls
    a.txt  test
    [root@linuxprobe test]# ls
    a.txt  test
    [root@linuxprobe test]# [ -e a.txt ] || mkdir test3  ## a.txt存在,不执行|| 后面的语句
    [root@linuxprobe test]# ls
    a.txt  test
    [root@linuxprobe test]# [ -e b.txt ] || mkdir test4  ## b.txt不存在,执行||后面的语句
    [root@linuxprobe test]# ls
    a.txt  test  test4

    2、结合使用

    [root@linuxprobe test]# [ -e a.txt ] && mkdir test5 || mkdir test6
    [root@linuxprobe test]# ls
    a.txt  test  test4  test5
    [root@linuxprobe test]# [ -e b.txt ] && mkdir test6 || mkdir test7
    [root@linuxprobe test]# ls
    a.txt  test  test4  test5  test7
    [root@linuxprobe test]# [ -e a.txt ] || mkdir test8 && mkdir test9  ## &&和||顺序无影响
    [root@linuxprobe test]# ls
    a.txt  test  test4  test5  test7  test9
    [root@linuxprobe test]# [ -e b.txt ] || mkdir test10 && mkdir test11
    [root@linuxprobe test]# ls
    a.txt  test  test10  test11  test4  test5  test7  test9
  • 相关阅读:
    mysql同步故障解决
    linux环境变量
    shell脚本中的交互式输入自动化
    ERROR oslo_service.service PlacementNotConfigured 解决办法
    openstack源
    rabbitmq——用户管理
    linux lvm扩容
    UWB DWM1000 开源项目框架 之 信号强度指示RSSI
    UWB DWM1000 开源项目框架 之 温度采集
    UWB DWM1000 开源项目框架
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/13814070.html
Copyright © 2011-2022 走看看