Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: ${=variable} doesn't always produce an array -- why?



Bart Schaefer wrote:
>zsh% one="one"
>zsh% two="one two"
>zsh %echo ${${=one}[1]} ${${=two}[1]}
>o one
>
>This seems unintuitive to me.  I was expecting to get the entire word "one"
>in both cases.

Ceteris paribus, I'd agree with your analysis of the above situation.
But to have ${one[1]} expand to "one" when SH_WORD_SPLIT is enabled
might be considered worse.

OTOH, I've been thinking that it might be better to adopt the ksh view
of scalar variables, that they are actually arrays of a single element.
That would make ${one[1]} in the above unambiguously refer to "one",
and make $= behave as you expected.  It would also break a lot of
existing scripts in ways that could only partially be fixed by another
compatibility option.

-zefram



Messages sorted by: Reverse Date, Date, Thread, Author