Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Is quoting of the assigned value needed?
On Fri, 2019-11-22 at 08:07 -0600, Perry Smith wrote:
> It surprised me that this:
>
> var2=$var1
>
> worked as it does but bash does the same thing.
It's much clearer like this as you can instantly see if you're doing an
array assignment or not.
If you like unclarity, the original zsh behaviour (changed in very
early days) is still available as an option...
GLOB_ASSIGN <C>
If this option is set, filename generation (globbing) is per‐
formed on the right hand side of scalar parameter assignments of
the form `name=pattern (e.g. `foo=*'). If the result has more
than one word the parameter will become an array with those words
as arguments. This option is provided for backwards compatibility
only: globbing is always performed on the right hand side of
array assignments of the form `name=(value)' (e.g. `foo=(*)') and
this form is recommended for clarity; with this option set, it is
not possible to predict whether the result will be an array or a
scalar.
What you appear to be suggesting is unsurprising (I think, I'm guessing
somewhat) is even less clear: look at the details of what's in $var1 and
decide based on that if you need an array. Obviously it can't *always*
assign an array as there would be no way of assigning scalar values.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author