title: Why doesn't Bash overwrite my array with a new one?
body: <p>I stripped my use case to these 3 lines (plus the output):</p>
  
  <pre><code>A=(foo bar)
  A=$(echo "spam egg")
  echo ${A[@]}
  spam egg bar
  </code></pre>
  
  <p>It creates an array with two element written by hand. Then some time later I want to replace my array with the output from a command line tool (e.g. <code>ls *.vhd</code>). Instead of replacing the array, Bash only replaces the first element, so bar gets "attached" at the end.</p>
  
  <p>If I use another handwritten array, then I can't reproduce this behavior.</p>
  
  <pre><code>A=(foo bar)
  A=(spam egg)
  echo ${A[@]}
  spam egg
  </code></pre>
  
  <p>So I suspect it's related to using <code>$()</code>. How can I solve my problem?</p>