title: Check if a directory exists and is accessible
body: <p>I want to check if a directory exists and it has access rights; if it does, then perform the tasks. This is the code I wrote, which might not have proper syntax.</p>
  
  <p>Can you help me to correct it?</p>
  
  <pre><code>dir_test=/data/abc/xyz
  if (test -d $dir_test &amp; test –x $dir_test -eq 0);
   then
  cd $dir_test
  fi
  </code></pre>
  
  <p>I believe this can also be written like this.</p>
  
  <pre><code>dir_test=/data/abc/xyz
  test -d $dir_test
  if [ $? -eq 0 ];
  then
  test –x $dir_test
  if [ $? -eq 0 ];
  then
  cd $dir_test
  fi
  fi
  </code></pre>
  
  <p>How can we write this more efficiently? </p>