i have a question
i try some function like
if [ -d "$DIR" ]; then
if [ -f "$DIR" ]; then
You can use
ls -A for this:
if [ "$(ls -A $DIR 2> /dev/null)" == "" ]; then # The directory is empty fi
-A shows all hidden files and directories except the
.. that are always there, so it will be blank in an empty directory and non-blank in a directory with any files or subdirectories.
2> /dev/null throws away any error messages
ls may print (note that checking a non-existant directory will yield a false positive, but you said you already checked that it existed). Checking a directory where you do not have read access also yields a false positive.