小编use*_*030的帖子

bash shell脚本只有在没有文件的情况下才能删除目录

好的,我正在编写一个shell脚本来删除一个目录,但只有在里面没有文件的情况下.

我想要做的是有一个if语句,它将检查目录中是否有文件,是否有文件询问用户是否要先删除文件然后删除目录.

我已经看了很多,并找到了一种方法来检查目录中是否存在文件,但我无法让它超过该阶段.

这是我到目前为止创建的if语句,用于检查目录中是否存在文件:

echo "Please type the name of the directory you wish to remove "

                read dName
        shopt -s nullglob
        shopt -s dotglob
        directory=$Dname

        if [ ${#directory[@]} -gt 0 ];
        then
                echo "There are files in this directory! ";
        else
                echo "This directory is ok to delete! "
        fi
        ;;
Run Code Online (Sandbox Code Playgroud)

unix bash shell

1
推荐指数
1
解决办法
3007
查看次数

标签 统计

bash ×1

shell ×1

unix ×1