美文网首页
条件判断示例

条件判断示例

作者: 迷糊银儿 | 来源:发表于2019-09-26 14:56 被阅读0次

1.遍历判断某目录下的所有文件与目录

#!bin/bash

dir="/Users/qufang01/Desktop/*"
for file in `ls $dir`
do
   if [ -f $dir"/"$file ]
    then echo $dir"/"$file is a file '\n'
   elif [ -d $file ]
    then echo $dir"/"$file is a dictionary '\n'
   fi
done
  1. 判断文件是否存在或文件大小
#!bin/bash

if [ -e $1 ]
   then echo $1  exists
elif [ -r $1 ]
   then echo $1 存在且是可读
elif [ -s $1 ]
   then echo $1文件存在且大小不为0
fi

相关文章

网友评论

      本文标题:条件判断示例

      本文链接:https://www.haomeiwen.com/subject/llqvyctx.html