title: How do I check if certain files exist in Bash?
body: <p>In a <code>bash</code> script, I have to check for the existence of several files.</p>
  
  <p>I know an awkward way to do it, which is as follows, but that would mean that my main program has to be within that ugly nested structure:</p>
  
  <pre><code>if [ -f $FILE1 ]
  then
  if [ -f $FILE2 ]
  then
    echo OK
    # MAIN PROGRAM HERE
  fi
  fi
  </code></pre>
  
  <p>The following version does not work:</p>
  
  <pre><code>([ -f $FILE1 ] &amp;&amp; [ -f $FILE2 ]) ||  ( echo "NOT FOUND"; exit 1 )
  echo OK
  </code></pre>
  
  <p>It prints</p>
  
  <pre><code>NOT FOUND
  OK
  </code></pre>
  
  <p>Is there an elegant way to do this right? </p>
  
  <p><strong>UPDATE:</strong> See the accepted answer. In addition, in terms of elegance I like <a href="https://stackoverflow.com/questions/572206/bash-how-do-i-check-if-certain-files-exist/572546#572546">Jonathan Leffler's answer</a>:</p>
  
  <pre><code>arg0=$(basename $0 .sh)
  error()
  {
      echo "$arg0: $@" 1&gt;&amp;2
      exit 1
  }
  
  [ -f $FILE2 ] || error "$FILE2 not found"
  [ -f $FILE1 ] || error "$FILE1 not found"
  </code></pre>