title: Why return value from a function following local declaration in bash is always 0?
body: <p>In a script of bash below, I declare a variable followed by a function. And I tried to get the return value of the function. It should be 1 but it was always 0. When I remove the local declaration, it works as I want.
   Why local declaration breaks the return value of the following function?
   Is local declaration a type of command, like "if []"?
   Please let me know the reason.</p>
  
  <p>My test function is following,</p>
  
  <pre><code>function inner_func() {
    local RETURN_00=1
    echo "RETURN_00 = $RETURN_00"
    echo "RETURN_00 = $RETURN_00" &gt;&amp;2
    return $RETURN_00
  }
  
  function func() {
    local ECHO_00=$(inner_func)  # this local declaration is a problem
    local RETURN_01=$?
    echo "RETURN_01 = $RETURN_01"
    echo "RETURN_01 = $RETURN_01" &gt;&amp;2
    return $RETURN_01
  }
  
  ECHO_01=$(func)
  RESULT=$?
  echo "RESULT = $RESULT"
  </code></pre>
  
  <p>Results of above code are following</p>
  
  <pre><code>RETURN_00 = 1
  RETURN_01 = 0
  RESULT = 0
  </code></pre>