if 判断 多个目录/多个文件是否同时存在 _shell

多个目录 if 判断

if  [ -d "/opt/dingtalk/" -a -d "/opt/goolge/" ] 
chengjiu_su@Pc:~/tmp$ cat dir.bash 
#!/bin/bash
if  [ -d "/opt/dingtalk/" -a -d "/opt/goolge/" ]    #运算符 -a 逻辑and 有1 不存在即为条件不成立
#if  [ -d "/opt/dingtalk/" -o -d "/opt/test/" ]     #运算符 -o 逻辑or 有1 存在即为条件成立
then                                     #/opt/test/目录路径 不存在
    echo "检测到目录存在"
else
    echo "未检测到目录存在,程序异常退出"
    exit 1 
fi 

多个文件 if 判断

if [ -f "1.txt" -a -f "2.txt" -a -f "3.txt" ]
chengjiu_su@Pc:~/tmp$ cat file.bash 
#!/bin/bash
if [ -f "1.txt" -a -f "2.txt" -a -f "3.txt" ]  #此处判断原理与上 目录判断原理一致
#if [ -f "1.txt" -a -f "2.txt" -o -f "4.txt" ]          
then                                      #4.txt文件不存在
    echo "检测文件存在"
else
    echo "未检测到文件,程序异常退出"
    exit 1
fi
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。