I have a shell script that get's directory path from user, but i need to check directory empty or not. In case user put his home path with ~
instead of absolute path, so I can't check it with ls
echo "Specify your project root directory. For example: ~/Base/project1"
read directory
if [ ! -z "$directory" ]
then
if [ "$(ls -A "$directory")" ]
then
echo Directory $directory is not empty
else
echo The directory $directory is empty '(or non-existent)'
fi
directory="$directory"
else
echo "No root directory specified. Exiting.."
exit;
fi
I'm getting error: ls cannot read path with ~ , how to expand it before checking directory is empty?