help-bash
[Top][All Lists]
Advanced

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

[Help-bash] How to replace a number of substrings simultaneously?


From: Peng Yu
Subject: [Help-bash] How to replace a number of substrings simultaneously?
Date: Sat, 19 Oct 2019 19:48:43 -0500

Hi,

I'd like to replace a number of substrings in a string simultaneously in bash.

For example, replace "s1" by $s1, replace "s2" by $s2,...

Something like this will not work robustly, because if $s1 is "s2",
then there will be two $s2 in the result.

x=${x//s1/$s1}
x=${x//s2/$s2}

It can be relatively easy to achieve this in other languages. But it
is not clear what might be the most succinct way to achieve it in
bash.

Does anybody know? Thanks.

-- 
Regards,
Peng



reply via email to

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