title: Why is bash errexit not behaving as expected in function calls?
body: <p>In the bash man page, it states:</p>
  
  <blockquote>
    <p>Exit immediately if a pipeline (which may consist of a single simple command),<br>
    a subshell command enclosed in parentheses, or one of the commands executed as
    part of a command list enclosed  by  braces...</p>
  </blockquote>
  
  <p>So I assumed that a function should be considered a command list enclosed by braces.  However, if you apply a conditional to the function call, errexit no longer persists inside the function body and it executes the entire command list before returning.  Even if you explicitly create a subshell inside the function with errexit enabled for that subshell, all commands in the command list are executed.  Here is a simple example that demonstrates the issue:</p>
  
  <pre><code>function a() { b ; c ; d ; e ; }
  function ap() { { b ; c ; d ; e ; } ; }
  function as() { ( set -e ; b ; c ; d ; e ) ; }
  function b() { false ; }
  function c() { false ; }
  function d() { false ; }
  function e() { false ; }
  </code></pre>
  
  <hr>
  
  <pre><code>( set -Eex ; a )
  + a
  + b
  + false
  </code></pre>
  
  <hr>
  
  <pre><code>( set -Eex ; ap )
  + ap
  + b
  + false
  </code></pre>
  
  <hr>
  
  <pre><code>( set -Eex ; as )
  + as
  + set -e
  + b
  + false
  </code></pre>
  
  <p>Now if I apply a conditional to each of them...</p>
  
  <pre><code>( set -Eex ; a || false )
  + a
  + b
  + false
  + c
  + false
  + d
  + false
  + e
  + false
  + false
  </code></pre>
  
  <hr>
  
  <pre><code>( set -Eex ; ap || false )
  + ap
  + b
  + false
  + c
  + false
  + d
  + false
  + e
  + false
  + false
  </code></pre>
  
  <hr>
  
  <pre><code>( set -Eex ; as )
  + as
  + set -e
  + b
  + false
  + c
  + false
  + d
  + false
  + e
  + false
  + false
  </code></pre>