Ok so I am writing a shell script to delete a directory but only if there are no files inside.
what I want to do is have an if statement that will check if there are files in the directory and if there are files ask the user if they want to delete the files first and then delete the directory.
I have looked quite a bit into this and have found a way to check if files exist in the directory but I haven't been able to make it past that stage.
here is the if statement I have created so far to check if files exist in a directory:
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
;;
rmdir
already does this by default. – Awful$@
and$n
variables instead of (or at least supplemental to) keyboard interaction. – Geilich