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

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



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@xxxxxx>       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.



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