On 9/1/22 12:54 PM, Aloxaf Yin wrote:
Hello, I encountered something strange when using bash. It seems like a bug
so someone suggested that I ask here.
Here is the test code.
declare -a arr=(12 34 56 78 90)
IFS=','
cat <<<"${arr[*]:0}"
cat <<EOF
${arr[*]:0}
${arr[*]}
EOF
The result is as follows. As you can see the comma is missing from the
second line.
12,34,56,78,90
12 34 56 78 90
12,34,56,78,90
It does seem strange. Here-document bodies don't undergo word splitting, so
the expansion of $* and ${arr[@]} should separate the words with the first
character of $IFS. The current bash behavior is compatible with ksh93, but
the behavior has varied between versions.
I'll look at it after bash-5.2 is released.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/