title: How can I check if a given directory is accessible?
body: <p>I am currently writing a script that will list all specific files in a directory. What I need the script to do is to verify that the directory is accessible. I am currently using this bit of code:</p>
  
  <pre><code># variable used to get the file permissions of the given  directory 
  perm=$(stat -c %a "$dir_name")
  
  if [ "$perm" != "755" -o "$perm" != "777" ]; then
    echo ERROR: "Directory $dir_name cannot be accessed check permissions"
    echo USAGE: "ass2 &lt;directory&gt;"
    exit 3
  fi
  </code></pre>
  
  <p>This will work for checking if they have those specific octal permissions, but I was wondering if there is any other way to check if the directory is accessible or not, and to return an error if it isn't.</p>