linux bash shell 判断目录是否为空的函数

#!/bin/sh
##方法一 判断输出字符数统计为0
is_empty_dir(){ 
    return `ls -A $1|wc -w`
}
##方法二 判断输出string为空
#is_empty_dir(){ 
#   return $[ -z `ls -A $1` ]
#}

if is_empty_dir $1
then
    echo " $1 is empty"
else
    echo " $1 is not empty"    
fi

注:参考连接:http://blog.csdn.net/10km/article/details/50427281

posted @ 2017-10-09 19:38  DamonWong  阅读(11720)  评论(0编辑  收藏  举报