1. 程式人生 > >linux bash shell 判斷目錄是否為空的函數

linux bash shell 判斷目錄是否為空的函數

http urn $1 參考 empty 判斷 details art lin

#!/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

linux bash shell 判斷目錄是否為空的函數