I'm trying to put a third check whether the directory contains only hidden files:
if [ ! "$(ls -A "$dir")" ]; then
echo "Specified directory is empty"
exit 1
elif [[ -z "$(find "$dir" -maxdepth 1 -type f)" ]]; then
echo "Specified directory contains only subdirectories and no files"
exit 1
elif [[ -z "$(find "$dir" -maxdepth 1 -type f | grep -v '"$dir"/.*')" ]]; then
echo "Specified directory contains only hidden files"
exit 1
fi
The third check is what is not working. I tried getting a list of all files that don't match '.*' and checking if it's empty with -z, but it always tests true. Do you have an idea?