[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bash tries to parse comsub in quoted PE pattern
From: |
Chet Ramey |
Subject: |
Re: bash tries to parse comsub in quoted PE pattern |
Date: |
Thu, 19 Oct 2023 16:12:16 -0400 |
User-agent: |
Mozilla Thunderbird |
On 10/18/23 1:08 PM, Emanuele Torre wrote:
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.
We can get closer with changes to how the command substitutions are
parsed while performing brace expansion.
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 +.
[...]
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.
It behaves as you want in posix mode. Here's the comment explaning it:
/* The big hammer. Single quotes aren't special in double quotes. The
problem is that Posix used to say the single quotes are semi-special:
within a double-quoted ${...} construct "an even number of
unescaped double-quotes or single-quotes, if any, shall occur." */
/* This was changed in Austin Group Interp 221 */
Bash in default mode uses its historical behavior, which is what POSIX
originally specified.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
Re: bash tries to parse comsub in quoted PE pattern, Chet Ramey, 2023/10/18
- Re: bash tries to parse comsub in quoted PE pattern, Emanuele Torre, 2023/10/18
- Re: bash tries to parse comsub in quoted PE pattern, Chet Ramey, 2023/10/18
- Re: bash tries to parse comsub in quoted PE pattern, Chet Ramey, 2023/10/18
- Re: bash tries to parse comsub in quoted PE pattern, Emanuele Torre, 2023/10/18
- Re: bash tries to parse comsub in quoted PE pattern,
Chet Ramey <=
- Re: bash tries to parse comsub in quoted PE pattern, Emanuele Torre, 2023/10/21