title: What's the correct way to redirect both stdout and stderr in bash?
body: <p>Here's the concrete task I'm trying to accomplish. zsh behaves the way I like</p>
  
  <pre><code>$ zsh
  $ which clang &gt; /dev/null 2&amp;&gt;1 &amp;&amp; echo clang || echo gcc
  clang
  $ which doesntexist &gt; /dev/null 2&amp;&gt;1 &amp;&amp; echo doesntexist || echo gcc
  gcc
  </code></pre>
  
  <p>But, in bash:</p>
  
  <pre><code>$ bash
  $ which clang &gt; /dev/null 2&amp;&gt;1 &amp;&amp; echo clang || echo gcc
  gcc
  </code></pre>
  
  <p>Here's the general case:</p>
  
  <pre><code>$ which clang &gt; /dev/null 2&amp;&gt;1; echo $?
  1
  $ which clang; echo $?
  /usr/bin/clang
  0
  </code></pre>
  
  <p>There's something wrong with how I'm redirecting output. What's the right way?</p>