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