Re: readarray leaves a NULL char embedded in each element

2024-06-24 Thread Greg Wooledge
On Mon, Jun 24, 2024 at 20:01:45 +0200, Davide Brini wrote: > $ ./printarg "${X[0]}A" > 65 32 65 0 83 > > That is, "A", a space, and "A" again (which is the result of the quoted > expansion), 0 for the string terminator, and a random 83 which is > whatever follows in memory (strangely, it seems to

Re: readarray leaves a NULL char embedded in each element

2024-06-24 Thread Davide Brini
On Mon, 24 Jun 2024 20:01:45 +0200, Davide Brini wrote: > On Mon, 24 Jun 2024 10:50:15 -0600, Rob Gardner > wrote: > > and a random 83 which is whatever follows in memory (strangely, it seems > to be 83 consistently though). Some more investigation shows that the "S" is the beginning of "SHELL=

Re: readarray leaves a NULL char embedded in each element

2024-06-24 Thread Greg Wooledge
On Mon, Jun 24, 2024 at 10:50:15 -0600, Rob Gardner wrote: > Description: > When using space or newline as a delimiter with readarray -d, > > elements in the array have the delimiter replaced with NULL, > > which is left embedded in each element of the array. This isn't p

Re: readarray leaves a NULL char embedded in each element

2024-06-24 Thread Davide Brini
On Mon, 24 Jun 2024 10:50:15 -0600, Rob Gardner wrote: [reformatted] > $ readarray -d ' ' X <<< "A B C" This does not remove the separator, so X[0] ends up containing "A ", X[1] contains "B ", and X[2] contains "C\n" (as there was no trailing space to terminate the string). See: $ declare -p X