I found a behavior of readarray that I can't get to the bottom of myself.The following code:readarray array < <(echo -e Jenny\nJane\nJessica)echo * Not enclosed:for ((i=0; i<${#array[@]}; i++)); do    echo ${array[$i]}doneecho * Enclosed:for ((i=0; i<${#array[@]}; i++)); do    echo ${array[$i]}doneProduces the following output:* Not enclosed:JennyJaneJessica* Enclosed:JennyJaneJessicaWhy exactly do elements become spaced out when they are enclosed with   like this?Even if I replaced echo ${array[$i]} with a variable like this:foo=${array[$i]}echo $fooThe output still becomes spaced out.But note that if I declared the array in the usual fashion array=(Jenny Jane Jessica) no spacing is inserted regardless of quotes.Reason why this is causing problems because I'm looping through an array and need to use the element inside a sentence and echo it. For example:readarray array < <(echo -e Jenny\nJane\nJessica)for ((i=0; i<${#array[@]}; i++)); do    echo Hello, ${array[$i]}!doneHowever ${array[$i]} is in-between   so \n gets inserted and the output becomes:Hello, Jenny!Hello, Jane!Hello, Jessica!
Why does an element of an array constructed with `readarray` gain a fictitious `\n` when it's enclosed in double quotes?
bash;array;newlines
It is because the readarray doesn't remove the delimiter (newline by default) unless it is called with the -t option.Using the simpler declare -p var to print array values, look at this:$ readarray array < <(echo -e Jenny\nJane\nJessica)$ declare -p arraydeclare -a array=([0]=$'Jenny\n' [1]=$'Jane\n' [2]=$'Jessica\n')You can see the trailing newlines for each element.While this:$ readarray -t array < <(echo -e Jenny\nJane\nJessica)$ declare -p arraydeclare -a array=([0]=Jenny [1]=Jane [2]=Jessica)does not have trailing newlines.The use of an unquoted variable expansion is just a bad idea, just don't.