help-bash
[Top][All Lists]
Advanced

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

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


From: Zephyr Waitzman
Subject: Re: [Help-bash] How to replace a number of substrings simultaneously?
Date: Sun, 20 Oct 2019 10:49:10 +0800

Using tr from coreutils?

On Sunday, October 20, 2019, Peng Yu <address@hidden> wrote:

> 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
>
>

-- 
GNU powered it...
GPL protect it...
GOD blessing it...

Regards,
Wi24rd 王滋涵


reply via email to

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