Why bash Substring Expansion doesn't respect IFS when using Heredoc

Viewed 54

Here is the test code.

declare -a arr=(12 34 56 78 90)

IFS=','

cat <<<"${arr[*]:0:3}"

cat <<EOF
${arr[*]:0:3}
${arr[*]}
EOF

And the results:

❯ bash test.sh
12,34,56
12 34 56
12,34,56,78,90

❯ zsh test.sh
12,34,56
12,34,56
12,34,56,78,90

As you can see, the , of the second line is missing when using bash.

0 Answers
Related