title: Local variables in Bash like in Perl?
body: <p>It seams wrong to repeat the same string twice</p>
  
  <pre><code>grep -q '+::::::' /etc/passwd || echo '+::::::' &gt;&gt; /etc/passwd
  </code></pre>
  
  <p>but if I do</p>
  
  <pre><code>{
  local a='+::::::'
  local b="/etc/passwd"
  grep -q $a $b || echo $a &gt;&gt; $b
  }
  </code></pre>
  
  <p>bash complains</p>
  
  <pre><code>-bash: local: can only be used in a function
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>Is there a way to do local variables in Bash similar to how Perl does with the <code>{ ... }</code>?</p>