I stripped my use case to these 3 lines (plus the output):
A=(foo bar)
A=$(echo "spam egg")
echo ${A[@]}
spam egg bar
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. ls *.vhd
). Instead of replacing the array, Bash only replaces the first element, so bar gets "attached" at the end.
If I use another handwritten array, then I can't reproduce this behavior.
A=(foo bar)
A=(spam egg)
echo ${A[@]}
spam egg
So I suspect it's related to using $()
. How can I solve my problem?