I need to test in a bash script if a given user can read a given directory with all files and sub-directories inside. The script runs as root.
Assuming the given user name is $user
and the directory to test is $dir
I added the following line to the script
su -m $user -c "test -r $dir && test -x $dir" if [ $? -ne ]; then echo "$dir is not readable or executable" fi
Would you suggest correct or improve it?