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

Re: Is this a bug? Why not?



On 2010-03-30 at 22:46 -0700, Bart Schaefer wrote:
> macadamia% print $ZSH_VERSION $ZSH_PATCHLEVEL
> 4.3.10-dev-1 1.4947
> macadamia% print ${var-???}
> CVS Doc Etc Src
> macadamia% print ${${var}-???}
> 
> macadamia% print ${${var}+???}
> CVS Doc Etc Src
> macadamia% print ${${var}:-???}
> CVS Doc Etc Src
> macadamia% print ${${var}:+???}
> 
> macadamia%

So the string ${var} when treated as a variable-name is empty but
defined?  The four expansions with a nested ${var} are entirely
consistent with the behaviour when expanding a variable which is defined
with a value of length 0.

Seems unusual, but consistent.

In bash, ksh, bad substitution.  In ksh93, it gets weird:
  $ echo ${var-???}
  OSM SCM bin dbg doc etc lib man src tmp www
  $ echo ${${var}-???}
  ksh93: syntax error: `!' unexpected

The ksh reference-name expansion made me think of the somewhat opposite
expansion in zsh, (P)var ...

Hrm, zsh 4.3.10 1.4705:

  % print ${(P)-???}
  zsh: 0239BCJPXZgiklms: ??
  % print ${(P)+???}
  zsh: bad substitution
  % print ${(P):-???}
  OSM SCM bin dbg doc etc lib man src tmp www
  % print ${(P):+???}

  %

Strange that the first entry is somehow tying into expanding $- for the
shell options ...

  % print ${-}
  0239BCJPXZgiklms
  % print ${(P)-}

  % print ${(P)-?}
  zsh: 0239BCJPXZgiklms: parameter not set

That strikes me as dubious.  You?



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