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

Comments

Leave a Reply