On Fri, Jan 26, 2018 at 11:31:40AM +0100, Klemens Nanni wrote:
> On Fri, Jan 26, 2018 at 09:41:45AM +0100, Klemens Nanni wrote:
> > On Wed, Jan 24, 2018 at 04:15:24PM +0100, [email protected] wrote:
> > > I found a bug in ksh's parameter expansion on an edge case:
> > >
> > > true $(true "${USER#'"'}")
> > >
> > > /home/sh[4]: no closing quote
> > >
> > > The problem seems to occurs when all of these conditions are present:
> > >
> > > 1. On ${var#pattern} or ${var%pattern} parameter expansion
> > > 2. When the pattern contains a singly quoted double quote: '"'
> > > 3. While expansion occurs withing $(...), (but not `...`)
> > > 4. While the expansion is quoted: "${var#pattern}".
> > As anton@ pointed out, this is known behaviour. The following will work:
> >
> > true $(true "${USER#\"}")
> > true $(true "${USER#"\""}")
> >
> Forgot to mention: `` are not subject to this, the bug lives in $() alone.
>From the end of ksh(1)
BUGS
$(command) expressions are currently parsed by finding the closest
matching (unquoted) parenthesis. Thus constructs inside $(command) may
produce an error. For example, the parenthesis in ‘x);;’ is interpreted
as the closing parenthesis in ‘$(case x in x);; *);; esac)’.