title: bash command substitution on external script function receives incorrect exit status
body: <p>This example was tested on Mac El Capitan with bash</p>
  
  <p>main_script.sh: </p>
  
  <blockquote>
    <p>NOTE: func_a and func_b are identical except for the line that the local variable <code>output</code> is declared.</p>
  </blockquote>
  
  <pre><code>func_a () {
      local output
      output="$(./external.sh some_function)"
      if [ $? -eq 0 ];then
          echo "A zero result ($?) -&gt; $output &lt;- end"
      else
          echo "A other result ($?) -&gt; $output &lt;- end"
      fi
  }
  
  func_b () {
      local output="$(./external.sh some_function)"
      if [ $? -eq 0 ];then
          echo "B zero result ($?) -&gt; $output &lt;- end"
      else
          echo "B other result ($?) -&gt; $output &lt;- end"
      fi
  }
  
  func_a
  func_b
  </code></pre>
  
  <p>external.sh:</p>
  
  <pre><code>some_function () {
      echo "this is the output"
      return 1
  }
  
  "$@"
  </code></pre>
  
  <p>When i run main_script the output is:</p>
  
  <pre><code>A other result (1) -&gt; this is the output &lt;- end
  B zero result (0) -&gt; this is the output &lt;- end
  </code></pre>
  
  <p>For what reason would the declaration of a local variable on the same line as the command substitiution affect the results?  Could this be a bug or am i missing something?</p>