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
  • 相关阅读:
    Spark RDD操作(1)
    scala学习笔记(8): 列表的map,flatMap,zip和reduce
    (转)hadoop基本操作命令
    Mac下配置环境变量
    Spark快速入门(1)
    urllib2 request 模拟伪装浏览器
    linux下面Zookeeper的单机模式(standalone)
    linux redis安装
    python OCR 图形识别
    mysql 、慢查询、到底如何玩
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/13814070.html
Copyright © 2011-2022 走看看