title: How to combine bash commands with || and && operators?
body: <p>I am trying to do something <em>similar to</em> &quot;try.. catch&quot; with bash, for which I read from <a href="https://stackoverflow.com/a/22010339/4247485">this post</a> that a good option to somehow replicate try/catch is to use the || and &amp;&amp; operators.
  In my case, I have a piece of code supposed to zip some files, but the zip is actually empty, so it throw an error:</p>
  <pre><code>zip -v OUTPUT.zip file1 file2 &gt;&gt; $LOGFILE 2&gt;&amp;1
  </code></pre>
  <p>Then in the LOGFILE, I see:</p>
  <pre><code>zip error: Nothing to do! (OUTPUT.zip)
  zip warning: OUTPUT.zip not found or empty
  ...(continued error message)
  </code></pre>
  <p>So I do this instead, to &quot;catch the error&quot;</p>
  <pre><code>{ zip -v OUTPUT.zip file1 file2 &gt;&gt; $LOGFILE 2&gt;&amp;1 } || { printf &quot;Error while zipping!&quot; &gt;&gt; $LOGFILE &amp;&amp; exit 1 }
  </code></pre>
  <p>..which partially works. It does exit the code, but <strong>doesn't do the printf</strong> command (or at least I can't see it in the LOGFILE).</p>
  <p>Also, <strong>although it encounters the &quot;exit 1&quot; command</strong> (on line 115), I also have the message (line 120 is my last line):</p>
  <pre><code>line 120: syntax error: unexpected end of file
  </code></pre>
  <p>What is wrong in my command? Why doesn't it do the print, and why the &quot;unexpected end of file&quot; message? Sorry if this question is more related to general bash programming than to the use of || &amp;&amp;, but I didn't know how to categorize this otherwise.</p>
  <p>Thanks a lot!</p>