* ${=variable} doesn't always produce an array -- why?
@ 1998-06-09 19:41 Bart Schaefer
1998-06-09 20:11 ` Zefram
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 1998-06-09 19:41 UTC (permalink / raw)
To: zsh-workers
Is there any way to cause a scalar to be interpreted as an array regardless
of the number of words it contains? Consider:
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.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ${=variable} doesn't always produce an array -- why?
1998-06-09 19:41 ${=variable} doesn't always produce an array -- why? Bart Schaefer
@ 1998-06-09 20:11 ` Zefram
1998-06-10 6:40 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Zefram @ 1998-06-09 20:11 UTC (permalink / raw)
To: Bart Schaefer; +Cc: zsh-workers
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: ${=variable} doesn't always produce an array -- why?
1998-06-09 20:11 ` Zefram
@ 1998-06-10 6:40 ` Bart Schaefer
0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 1998-06-10 6:40 UTC (permalink / raw)
To: Zefram; +Cc: zsh-workers
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1998-06-10 6:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-06-09 19:41 ${=variable} doesn't always produce an array -- why? Bart Schaefer
1998-06-09 20:11 ` Zefram
1998-06-10 6:40 ` Bart Schaefer
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).