title: I just assigned a variable, but echo $variable shows something else
body: <p>Here are a series of cases where <code>echo $var</code> can show a different value than what was just assigned. This happens regardless of whether the assigned value was "double quoted", 'single quoted' or unquoted. </p>
  
  <p>How do I get the shell to set my variable correctly?</p>
  
  <p><strong>Asterisks</strong></p>
  
  <p>The expected output is <code>/* Foobar is free software */</code>, but instead I get a list of filenames:</p>
  
  <pre><code>$ var="/* Foobar is free software */"
  $ echo $var 
  /bin /boot /dev /etc /home /initrd.img /lib /lib64 /media /mnt /opt /proc ...
  </code></pre>
  
  <p><strong>Square brackets</strong></p>
  
  <p>The expected value is <code>[a-z]</code>, but sometimes I get a single letter instead!</p>
  
  <pre><code>$ var=[a-z]
  $ echo $var
  c
  </code></pre>
  
  <p><strong>Line feeds (newlines)</strong></p>
  
  <p>The expected value is a  a list of separate lines, but instead all the values are on one line!</p>
  
  <pre><code>$ cat file
  foo
  bar
  baz
  
  $ var=$(cat file)
  $ echo $var
  foo bar baz
  </code></pre>
  
  <p><strong>Multiple spaces</strong></p>
  
  <p>I expected a carefully aligned table header, but instead multiple spaces either disappear or are collapsed into one!</p>
  
  <pre><code>$ var="       title     |    count"
  $ echo $var
  title | count
  </code></pre>
  
  <p><strong>Tabs</strong></p>
  
  <p>I expected two tab separated values, but instead I get two space separated values!</p>
  
  <pre><code>$ var=$'key\tvalue'
  $ echo $var
  key value
  </code></pre>