bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: bash tries to parse comsub in quoted PE pattern


From: Emanuele Torre
Subject: Re: bash tries to parse comsub in quoted PE pattern
Date: Wed, 18 Oct 2023 19:08:42 +0200
User-agent: Mutt/2.2.12 (2023-09-09)

On Wed, Oct 18, 2023 at 11:24:11AM -0400, Chet Ramey wrote:
> On 10/18/23 10:50 AM, Chet Ramey wrote:
> 
> > > Is it really ok to break that behaviour?
> > 
> > That's why, if you want the first problem repaired, you have to specify
> > which word expansions are ok to parse and which are not. Should it be
> > only command and process substitution, which can independently specify
> > brace expansions? Should it be other parameter expansions, which can
> > contain quoted strings and command substitutions? Neither? Both?
> 
> It looks like the answer is probably "neither."

I have examined the code, and I now understand why "${foo:-"{1..2}"}"
etc were allowed, but were not supposed to.

It is hard to specify a behaviour that preserves brace expansions in
double quoted parts within a parameter substitution.

I have no real reason to oppose to the removal of "${arr["{foo,bar}"]}"
and similar; I have only ever used that when golfing... I just wanted to
mention that it now does not work in case someone cared more about this
feature.

It could be allowed only in the double quoted parts of the parameter
expansions. But it is hard to tell when a double quote is literal or not
in a PE with the existing code, so maybe not worth doing if no one
cares. Removing this behaviour while fixing "${x#'`'}" is fine for me.


DDD


While we are at it, when examining this issue now, I have also noticed
that, regardless of whether brace expansion is enabled or not, the bash
parser always reads single quotes in double quoted PEs as if they are
not literal, even though they are literal if the PE is -, =, or +.

For example:

  $ bash -c "echo x\"\${foo-'}"
  bash: -c: line 1: unexpected EOF while looking for matching `''
  bash: -c: line 2: syntax error: unexpected end of file
  $ bash -c "echo x\"\${foo-'$(echo hi >&2)'}"
  hi
  x''
  $ bash -c "echo \"\${foo#'$(echo hi >&2)'}"
  x

  $ # }" in single quotes does not terminate the PE even though the
  $ # single quote is supposed to be literal, and it will be interpreted
  $ # as literal
  $ printf %s\\n x"${foo:-'}" hello hi'}"
  x'} hello hi'

Could/Should this also be fixed so that  "${foo:-'}"  (and +, and =) is
read correctly? Other shells including ksh93, mksh, dash, NetBSD ash,
and busybox can read it correctly.

The only shell I found that does not handle that correctly other than
bash is pdksh, but only because it treats single quotes as not literal
even if the double quoted PE is +, - or =.

Thank you!
 emanuele6



reply via email to

[Prev in Thread] Current Thread [Next in Thread]