This question already has an answer here:


echo "tell me a word"
read the_word

How to replace all WordToReplace in a file by the_word?

sed does not seems to appreciate:

sed -i 's/WordToReplace/$the_word/g' thefile.sh

marked as duplicate by steeldriver, Community Mar 23 '16 at 3:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


Variables are not expanded within single quotes, they are treated literally then.

Use double quotes instead:

sed -i "s/WordToReplace/$the_word/g" thefile.sh

Not the answer you're looking for? Browse other questions tagged or ask your own question.