Remove all occurrences of a word from a string

Viewed 9065

I have the following string

str="toto1 toto2 toto3 toto4 toto2 toto5"

the toto2 occurs twice in the string. How can I remove all toto2 occurrences from the string?

I tried this:

echo ${str/toto2/}

But this will remove only the first occurrence of toto2.

toto1 toto3 toto4 toto2 toto5 # output

How can I remove all toto2 occurrences from the string?

1 Answers
Related