Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Confused about splitting
Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> writes:
> «${=g}» does split the value of the parameter 'g'; you can see that with
> «printf '[%s]' ${=g}». Then, that intermediate result — an array of words — is
> assigned to the parameter 'first' scalarly, so the value of $first is set to be
> the words of the array joined by spaces as a single string. That's why «echo
> $first» has the right output. The «echo $#first» line prints the length of the
> string "$first" in characters, because that's what the «$#foo» syntax does when
> foo is a scalar.
This mistaken idea came from the fact $first[1] is just e with
foofunc3. $first[2] is n, $first[3] is o and so on. For some reason I
thought scalars don't have that but they do.
> The fix is to add back the parentheses to make the assignment an array
> assignment: «first=( ${=g} )».
Thanks.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author