In a bash
script, how can I remove a word from a string, the word would be stored in a variable.
FOO="CATS DOGS FISH MICE"
WORDTOREMOVE="MICE"
bashshell-scriptvariable
In a bash
script, how can I remove a word from a string, the word would be stored in a variable.
FOO="CATS DOGS FISH MICE"
WORDTOREMOVE="MICE"
Best Answer
Try:
This also work in
ksh93
,mksh
,zsh
.POSIXLY:
It assumes your words are space delimited and has side effect that remove spaces before and after
"$WORDTOREMOVE"
.