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

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



On Jun 9,  9:11pm, Zefram wrote:
} Subject: 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.

Hrm.  I'm not so sure that -would- be worse.  If it were done that way,
then you'd get csh/ksh scalar behavior when emulating csh or ksh or sh,
-and- $=x would always "make an array" of x.

} 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.

No, to do that all the time would break way too many things, including
most of the useful things you can do with $BUFFER in zle widgets and a
whole lot of the sample compctl -K functions.

The first idea (tying it to SH_WORD_SPLIT), on the other hand, probably
won't do all that much harm; how many scripts that rely on SH_WORD_SPLIT
also require zsh scalar-indexing behavior?  Can we see a show of hands?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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