0

I have a sed command something like this to comment out a particular line based on a particular pattern:

sed -e '/$OLD_VERSION/ s/^#*/#/' -i /ws/usernam/workspace/scripts/raw-vobs-config-spec

Here we need to comment out the line containing $OLD_VERSION. I have passed $OLD_VERSION as a parameter in my shell script.

paddy
  • 60,864
  • 6
  • 61
  • 103
noob_coder
  • 749
  • 4
  • 15
  • 35
  • 1
    Is it working in console ? – Thanga Feb 10 '16 at 06:09
  • See: [Difference between single and double quotes in bash](http://stackoverflow.com/q/6697753/3776858) – Cyrus Feb 10 '16 at 06:39
  • `a sed command something like this` != `this sed command`. Guess which one is required to help solve a problem you have with a given command. The command you posted will **NOT** do what you want no matter where you call it from. – Ed Morton Feb 11 '16 at 00:11

1 Answers1

1

When you use single quotes in a shell, it prevents ordinary variable expansion, and so $OLD_VERSION will not expand. Since you don't have any other characters requiring escaping, the fix should be as simple as using double-quotes:

sed -e "/$OLD_VERSION/ s/^#*/#/" -i /ws/usernam/workspace/scripts/raw-vobs-config-spec
paddy
  • 60,864
  • 6
  • 61
  • 103