title: How to create a local read-only variable in bash?
body: <p>How do I create both <code>local</code> and <code>declare -r</code> (read-only) variable in bash?</p>
  
  <p>If I do:</p>
  
  <pre><code>function x {
      declare -r var=val
  }
  </code></pre>
  
  <p>Then I simply get a global <code>var</code> that is read-only</p>
  
  <p>If I do:</p>
  
  <pre><code>function x {
      local var=val
  }
  </code></pre>
  
  <p>If I do:</p>
  
  <pre><code>function x {
      local var=val
      declare -r var
  }
  </code></pre>
  
  <p>Then I get a global again (I can access <code>var</code> from other functions).</p>
  
  <p>How to combine both local and read-only in bash?</p>