Bash string replace

Bash replace first substring match or all substring matches.

$ cat test.sh
find="b"
replace="B"
in="abcabc"
 
echo "find: ${find}"
echo "replace: ${replace}"
echo "in: ${in}"
 
echo "${in/$find/$replace}"
echo "${in//$find/$replace}"
$ bash test.sh
find: b
replace: B
in: abcabc
aBcabc
aBcaBc
If you liked this posting, please feel free to leave me a comment below.
View this page on GitHub.
Posted .

Comments

Leave a Reply