Andrew Hewus Fresh writes:
> On Sun, Dec 11, 2022 at 08:06:24PM -0500, Rob Whitlock wrote:
> > On line 408, fw_update has the expression ${LOCALSRC:#file:}. The parameter
> > substitution ${name:#word} is not documented in the manual page for ksh yet
> > its behavior seems to be equivalent to ${LOCALSRC#file:}. Assuming this is
> > a typo, a patch is provided to remove the colon. If it is not a typo, could
> > someone explain what this syntax does?
>
> It was a typo, committed, thanks!
>
>
> > Is this was a typo however, and this parameter substitution is not
> > officially supported, why did ksh not complain?
>
> Not having read it, I assume the implementation reads the : and sets a
> flag that says "must be be NULL" for the -, +, =, and ? substitutions
> and the validation that the next character is one of those four is
> missing.

It does this:

        /* allow :# and :% (ksh88 compat) */
        if (c == ':') {
                *wp++ = CHAR, *wp++ = c;
                c = getsc();
        }

... introduced in lex.c 1.11 in 1998. I think it's safe.

> An email to bugs@ with this question might get the attention of folks
> who are more familiar with ksh internals and whether fixing this being
> too accepting is worth the code and the likelihood of breaking scripts
> with typos like this one.

>From prior excavation deep in the bowels of yylex:

        ${-expansion expects a variable name and modifiers. The
        name is scanned for by get_brace_var below and then
        modification by ``#'' or ``%'' is detected. ``:#'' and
        ``:%'' are also accepted for compatibility with ksh88.

This seems like a good opportunity for shameless self-promotion of
the full excavation at http://zeus.jtan.com/~chohag/ksh/ (section
347 "Detect ${-expansion", page 147).

Matthew

Reply via email to