On 11/28/25 2:08 PM, Chet Ramey wrote:

The other question is what, if anything, to do about this in bash. Maybe
the right thing, since the bash-4.2 code doesn't do anything to quote the
ampersand specially, is to simply disable `&' replacement if the shell
compatibility level is <= 42. Another option would be to quote the
ampersand appropriately if the compatibility level is <= 42. Or, since
bash-4.2 dates from 2010, maybe the best thing is just to move forward.

I took a look at this, and I made some changes that better align the
behavior of pattern substitution when patsub_replacement is enabled between
bash-devel when BASH_COMPAT=42 and bash-4.2.

In particular, this makes your example -- an unquoted word expansion with
single-quoted pattern and replacement strings -- behave as it does in both
bash-4.2 and bash-5.3: not performing the `&' substitution.

These changes accommodate the difference that compat42 addresses -- not
performing quote removal on the replacement string -- while appropriately
quoting the `&' to produce something closer to the bash-4.2 behavior.

This doesn't temporarily disable patsub_replacement, so it's still possible
to use pattern substitution with replacement even when BASH_COMPAT == 42.

These changes will be in the next devel branch push. Please test them out
and let me know your results.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [email protected]    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature

Reply via email to