* foo=($bar) vs foo=("$bar[@]")
@ 1997-01-29 5:07 Roderick Schertler
1997-01-29 8:14 ` Peter Stephenson
1997-01-29 15:17 ` Zefram
0 siblings, 2 replies; 4+ messages in thread
From: Roderick Schertler @ 1997-01-29 5:07 UTC (permalink / raw)
To: zsh-users
The NEWS file says
foo=$bar no longer creates an array even if bar is an array. Use
foo=( $bar ) or even better, foo=( "$bar[@]" ) instead.
In what way is "$bar[@]" better than $bar? The extra line noise is a
point in favor of the simpler form, what benefit outweighs it?
I hope it's not just that it makes ksh programmers feel at home! Being
able to say just $bar is one of zsh's big advantages in array handling.
--
Roderick Schertler
roderick@gate.net
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: foo=($bar) vs foo=("$bar[@]")
1997-01-29 5:07 foo=($bar) vs foo=("$bar[@]") Roderick Schertler
@ 1997-01-29 8:14 ` Peter Stephenson
1997-01-29 15:17 ` Zefram
1 sibling, 0 replies; 4+ messages in thread
From: Peter Stephenson @ 1997-01-29 8:14 UTC (permalink / raw)
To: Zsh users list, Roderick Schertler
Roderick Schertler wrote:
> The NEWS file says
>
> foo=$bar no longer creates an array even if bar is an array. Use
> foo=( $bar ) or even better, foo=( "$bar[@]" ) instead.
>
> In what way is "$bar[@]" better than $bar?
I think the point is it works even if shwordsplit is set.
% setopt shwordsplit
% args() { echo $#; }
% bar=('one word' 'another word')
% args $bar
4 # i.e. 'one' 'word' 'another' 'word'
% args "$bar[@]"
2 # i.e. 'one word' 'another word'
It still doesn't quite make ksh users feel it home, it needs to be
"${bar[@]}" for that. In fact, with ksharrays (or `emulate ksh')
turned on you need it in zsh too, so perhaps the NEWS file ought to
have that if it's trying to be all-inclusive.
--
Peter Stephenson <pws@ifh.de> Tel: +49 33762 77366
WWW: http://www.ifh.de/~pws/ Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, 15735 Zeuthen, Germany.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: foo=($bar) vs foo=("$bar[@]")
1997-01-29 5:07 foo=($bar) vs foo=("$bar[@]") Roderick Schertler
1997-01-29 8:14 ` Peter Stephenson
@ 1997-01-29 15:17 ` Zefram
1997-01-29 15:45 ` Roderick Schertler
1 sibling, 1 reply; 4+ messages in thread
From: Zefram @ 1997-01-29 15:17 UTC (permalink / raw)
To: Roderick Schertler; +Cc: zsh-users
Roderick Schertler wrote:
>In what way is "$bar[@]" better than $bar? The extra line noise is a
>point in favor of the simpler form, what benefit outweighs it?
"$bar[@]" works in all cases, but $bar will drop empty array elements:
% foo=(a '' b)
% bar1=($foo)
% bar2=("$foo[@]")
% echo $#foo $#bar1 $#bar2
3 2 3
Also $bar is at the mercy of several options, but in "$bar[@]"
everything is explicit.
-zefram
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: foo=($bar) vs foo=("$bar[@]")
1997-01-29 15:17 ` Zefram
@ 1997-01-29 15:45 ` Roderick Schertler
0 siblings, 0 replies; 4+ messages in thread
From: Roderick Schertler @ 1997-01-29 15:45 UTC (permalink / raw)
To: Zefram; +Cc: zsh-users
On Wed, 29 Jan 1997 15:17:35 +0000 (GMT), Zefram <zefram@dcs.warwick.ac.uk> said:
>
> "$bar[@]" works in all cases, but $bar will drop empty array elements:
Ouch, I didn't know that! I guess that shows how much zsh programming I
actually do.
--
Roderick Schertler
roderick@gate.net
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~1997-01-29 16:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-29 5:07 foo=($bar) vs foo=("$bar[@]") Roderick Schertler
1997-01-29 8:14 ` Peter Stephenson
1997-01-29 15:17 ` Zefram
1997-01-29 15:45 ` Roderick Schertler
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).