bug-bash
[Top][All Lists]
Advanced

[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 17:20:52 -0400

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.



reply via email to

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