1

Situation:

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
aurelien
  • 2,127

1 Answers1

4

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
heemayl
  • 56,300