Single Substitution is easy:
string="Mark Shuttleworth"
echo ${string/a/o}
Mork Shuttleworth
is it possible though to do a double at the same time?
echo ${string/a/o string/t/g} #doesn't work, but you get the idea
Mork Shuggleworgh
Regular Expressions suffice as an answer, if it is possible using them.
Thanks
As far as I know, the only way to do it in current versions of
bash
is in two steps e.g.Attempts to nest substitutions result in an error:
Note that other shells may support such nested substitutions e.g. in
zsh 5.2
:Of course, external tools such as
tr
,sed
,perl
can do it easilyYou're substituting single letters, so just use
tr
:This causes each
a
to be replaced byo
and eacht
to be replaced byg
. With your example:Try
I'm using my tablet, no
bash
to test.You may want to checkout using the
printf
command much more flexible.