[Top][All Lists]

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

Re: string substitution broken since 5.2

From: Greg Wooledge
Subject: Re: string substitution broken since 5.2
Date: Thu, 3 Nov 2022 19:48:26 -0400

On Thu, Nov 03, 2022 at 05:20:52PM -0400, Greg Wooledge wrote:
> On Fri, Nov 04, 2022 at 04:09:10AM +0900, Koichi Murase wrote:
> > When one wants to also support Bash 4.2, one possible workaround is to
> > assign the result to a variable (without quoting the right-hand side
> > of the assignment):
> > 
> > $ bash-4.2 -c 'string=\"hi\"; string=${string//\"/\"}; echo "$string"'
> > $ bash-4.2 -c 'str="a string"; rep="a&b"; str=${str//a/"$rep"}; echo "$str"'
> > 
> > These work as expected in all Bash versions I can test (2.0..5.2).
> That's amazingly clever.  You're forcing the semantics of double-quoting
> the right-hand side (implicitly, due to the simple assignment), without
> putting actual quotes in it.

Hmm, no, you *are* including quotes, so that's not why it works.
I actually have no idea why it works.  But that's OK.  I'm just happy
that it *does* work.

So far, that makes two cases where a temporary variable is the only
known workaround for incompatible changes introduced in bash 5.2:
parameter expansion with search-and-replace, and associative array
element access within an arithmetic context.

reply via email to

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