title: Bash: Hide global variable using local variable with same name
body: <p>I'd like to use a global variable in a function but don't want the change to go outside the function. So I defined a local variable initialized to the value of the global variable. The global variable has a great name, so I want to use the same name on the local variable. This seems doable in Bash, but I'm not sure if this is undefined behavior.</p>
  
  <pre><code>#!/bin/bash
  
  a=3
  echo $a
  foo() {
      local a=$a  ##  defined or undefined?
      a=4
      echo $a
  }
  foo
  echo $a
  </code></pre>
  
  <p>Gives output:</p>
  
  <pre><code>3
  4
  3
  </code></pre>