|
From: | Chet Ramey |
Subject: | Re: Substring Expansion doesn't respect IFS when using in Heredoc |
Date: | Fri, 2 Sep 2022 15:45:38 -0400 |
User-agent: | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.1 |
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 chet@case.edu http://tiswww.cwru.edu/~chet/
[Prev in Thread] | Current Thread | [Next in Thread] |