当前位置: 技术问答>linux和unix
求助 一个shell问题
来源: 互联网 发布时间:2015-12-13
本文导语: aaaa是个有文件的目录,bbbb是个没有文件的目录 # sh a.sh aaaa total 0 -rwxr----- 1 root sys 0 Sep 5 13:45 myfile the directory is not empty # sh a.sh bbbb total 0 the directory is not empty # more a.sh dir=$...
aaaa是个有文件的目录,bbbb是个没有文件的目录
# sh a.sh aaaa
total 0
-rwxr----- 1 root sys 0 Sep 5 13:45 myfile
the directory is not empty
# sh a.sh bbbb
total 0
the directory is not empty
# more a.sh
dir=$1
ls -l $dir
if [ -z " `ls -A $dir` " ]
then
echo "the directory is empty"
else
echo "the directory is not empty"
fi
执行错误 执行sh a.sh bbbb 应显示the directory is empty
那位大哥帮帮忙忙 谢谢
# sh a.sh aaaa
total 0
-rwxr----- 1 root sys 0 Sep 5 13:45 myfile
the directory is not empty
# sh a.sh bbbb
total 0
the directory is not empty
# more a.sh
dir=$1
ls -l $dir
if [ -z " `ls -A $dir` " ]
then
echo "the directory is empty"
else
echo "the directory is not empty"
fi
执行错误 执行sh a.sh bbbb 应显示the directory is empty
那位大哥帮帮忙忙 谢谢
|
if [ "x" = x"`ls -A $dir`" ]
then
echo "the directory is empty"
else
echo "the directory is not empty"
fi
这样改就可以了。
then
echo "the directory is empty"
else
echo "the directory is not empty"
fi
这样改就可以了。