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

Re: Modifiers and parameter expansion?



On Thu, Dec 1, 2022 at 6:48 PM Dominik Vogt <dominik.vogt@xxxxxx> wrote:
>
> On Thu, Dec 01, 2022 at 05:34:18PM -0800, Bart Schaefer wrote:
> > Not sure where you came up with that.
>
>   [Implicit: the braces can be omitted, unless]

OK ... but that didn't come from the context in the doc, which uses
the form with braces ${NAME} as the base case.

> (The implicit statement is the _only_ "mention" of the brace-less
> form at all.)

"with or without braces" is explicitly in the last sentence?  But
again the manual is largely written from the viewpoint of someone who
knows how shells work and therefore is familiar with the $NAME case
and needs to be told the way zsh might diverge from that.

> > ${=X}
> > ${~X}
> > ${#X}
> > ${+X}
>
> These work without braces even if KSH_ARRAYS is set.

Hmm, I would say that's a bug, then, in "emulate sh" if not in
KSH_ARRAYS.  $#X should be interpreted as ${#}X (and is, with "emulate
sh", even though there's no specific setopt controlling it).  Bash
doesn't even attempt to expand the other three, they're treated as not
being substitutions at all; you get an error only on e.g. ${+X}.

I suppose allowing them to work without braces is an extension in the
same way that supporting them with braces is an extension.




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