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

Re: foo=($bar) vs foo=("$bar[@]")



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



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