title: How does "set -e" work with subshells?
body: <p>I was wondering whether <code>set -e</code> propagates through subshells (i.e. does a subshell inherit the <code>-e</code> setting of its parent), so I made some experiments. I found some strange results that I can't explain.</p>
  
  <p>First, here are some basic tests. They return what I expect.</p>
  
  <pre><code>( true; false )         # 1
  ( false; true )         # 0
  ( set -e; false; true ) # 1
  </code></pre>
  
  <p>Now I tried what happens if I put a subshell within my subshell. This expression returns 1, which suggests that it propagates.</p>
  
  <pre><code>( set -e; ( false; true ) )
  </code></pre>
  
  <p>Then I tried these expressions. I expected them to return 1, but I found that they return 0.</p>
  
  <pre><code>( set -e; ( true; false ); true )
  ( set -e; ( set -e; false; true ); true )
  </code></pre>
  
  <p>Why? In both cases, the inner subshell returns 1, whether <code>set -e</code> propagates or not (as I checked in the beginning). The outer subshell has <code>set -e</code>, which means that it should fail after the inner subshell exits, but it does not. Can someone explain this?</p>