I’m trying to find and replacing some text using sed. Specifically, I’m trying to add quotes around a variable which could contain whitespaces.
sed -i 's/$VAR some.file/"$VAR" some.file/g' path/to/file
Unfortunately, the result is not expected. I’ve also tried to backslash the quotes, with no luck. What am I missing here?
The sed command is executed under Windows/cygwin.
You’re missing the fact that single quotes prevent variable substitution:
or even