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

RE: PATCH: 3.1.9-dev-8: Re: Word splitting in zsh



>
> This applies only to ${...+...} and ${...-...}, with or without the `:'.
> As I mentioned, there would be some benefit to also doing this for the
> ${...=...} forms, because then things like ${(A)foo="$bar[@]"} would work
> independently of the setting of shwordplit.
>

Is the following a bug in shell and should zsh emulate it?

bor@itsrm2% sh
$ set "a b c" 1 2
$ args ${foo="$@"}
3
a b c
1
2
$ args $foo
5
a
b
c
1
2

Compare with zsh:

bor@itsrm2% setopt shwordsplit
bor@itsrm2% set "a b c" 1 2
bor@itsrm2% print -l ${foo="$@"}
a
b
c
1
2

To explain what's going on:

In case of ${name-word} or ${name+word} sh does exactly *one* expansion (as
opposed to zsh that does two) with the pseudocode (e.g. for -)

if defined name
  replace $name
else
  replace expanded word

(BTW I was surprised to see that expansions in word actually nest;
${xxx-${yyy-bar}} results in ``bar'').

But in case of ${name=bar} the definition is

Assign Default Values. If parameter is unset or null, the expansion of word
will be assigned to parameter. In all cases, the final value of parameter will
be substituted. Only variables, not positional parameters or special
parameters, can be assigned in this way.

BUT sh has only scalar parameters - so, the "final value" can only be scalar
that it then word splitted - as happens in zsh :-) But it looks, like sh
behaves as in case of ${...-...}/${...+...} - i.e. it substitutes expansion of
word and assigns it to name. It smells like a bug in (our) sh to me.

-andrej

P.S. Deborah, it's probably becoming way too specific. Should we still Cc you?



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