0

I am writing a script in bash and I can remove a string from a sentence using the code below:

echo 'This is a foo test' | sed 's/\<foo\>//g'

OUTPUT: 'This is a test'

However, I want to be able to replace the foo with a variable. I tried the command below but it does not remove the values from the sentence.

temp="foo"
echo 'This is a foo test' | sed 's/\<$temp\>//g'

OUTPUT: 'This is a foo test'

muru
  • 197,895
  • 55
  • 485
  • 740
Ashim
  • 153

1 Answers1

2

Within single quotes the variable is not substituted (because $ has no special meaning withing single quotes). You can use double quotes instead:

echo 'This is a foo test' | sed "s/\<$temp\>//g"
xenoid
  • 5,504