title: Bash script to test if a given user can read a directory and all files inside?
body: <p>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 <em>root</em>.</p>
  
  <p>Assuming the given user name is <code>$user</code> and the directory to test is <code>$dir</code> I added the following line to the script</p>
  
  <pre>
  su -m $user -c "test -r $dir && test -x $dir"
  if [ $? -ne ]; then
     echo "$dir is not readable or executable"
  fi
  </pre> 
  
  <p>Would you suggest correct or improve it?</p>