title: Test multiple file conditions in one swoop (BASH)?
body: <p>Often when writing for the bash shell, one needs to test if a file (or Directory) exists (or doesn't exist) and take appropriate action.  Most common amongst these test are...</p>
  
  <p><code>-e</code> - file exists, <code>-f</code> - file is a regular file (not a directory or device file), <code>-s</code> - file is not zero size, <code>-d</code> - file is a directory, <code>-r</code> - file has read permission, <code>-w</code> - file has write, or <code>-x</code> execute permission (for the user running the test)</p>
  
  <p>This is easily confirmed as demonstrated on this <strong>user-writable directory</strong>....</p>
  
  <pre><code>#/bin/bash
  
  if [ -f "/Library/Application Support" ]; then
  echo 'YES SIR -f is fine'
  else echo 'no -f for you'
  fi
  
  if [ -w "/Library/Application Support" ]; then
  echo 'YES SIR -w is fine'
  else echo 'no -w for you'
  fi
  
  if [ -d "/Library/Application Support" ]; then
  echo 'YES SIR -d is fine'
  else echo 'no -d for you'
  fi
  </code></pre>
  
  <p><strong>➝ no -f for you  ✓<br>
  ➝ YES SIR -w is fine ✓<br>
  ➝ YES SIR -d is fine  ✓</strong></p>
  
  <p>My question, although seemingly obvious, and unlikely to be impossible - is how to simply <em>combine</em> these tests, without having to perform them separately for each condition...  Unfortunately...</p>
  
  <pre><code>if [ -wd "/Library/Application Support" ]  
    ▶  -wd: unary operator expected
  
  if [ -w | -d "/Library/Application Support" ]   
    ▶  [: missing `]'
    ▶  -d: command not found
  
  if [ -w [ -d "/Library.... ]]   &amp;  if [ -w &amp;&amp; -d "/Library.... ] 
    ▶  [: missing `]'
  </code></pre>
  
  <p><strong>➝ no -wd for you ✖<br>
  ➝ no -w | -d for you ✖<br>
  ➝ no [ -w [ -d .. ]] for you ✖<br>
  ➝ no -w &amp;&amp; -d for you ✖</strong></p>
  
  <p>What am I missing here?  </p>