0

I have a file named webroot with below contents:

ROOT= .
#ROOT = Current Directory for Installers. Specify in double quotes.

I want to replace value foe first occurrence of ROOT with the path in double quotes, for which I created below script

#!/bin/bash

ppath="$(dirname $(pwd))"

sed -i '0,/^ROOT.*/s/^ROOT.*/ROOT = \"\${ppath}\"/' webroot

grep -m1 ROOT webroot 

However, when I execute the script, I see below as output:

ROOT = "${ppath}"

Updated the script to below, however same result:

#!/bin/bash

ppath="$(dirname $(pwd))"

sed -i "0,/^ROOT.*/s/^ROOT.*/ROOT = \"\${ppath}\"/" webroot

grep -m1 ROOT webroot 

Any suggestions, how this can be fixed?

cool_stuff_coming
  • 443
  • 1
  • 6
  • 19
  • 2
    Research quoting in shell. How it works? How does single quotes differ from double quotes? etc. As for pattern itself - see https://stackoverflow.com/questions/407523/escape-a-string-for-a-sed-replace-pattern – KamilCuk Apr 22 '21 at 10:05
  • I've closed your previous question because it is a duplicate. Why are you opening another duplicate? – choroba Apr 22 '21 at 10:09
  • Because the link you provided in previous post suggested to put sed command in double quotes. And stackoverflow suggested to delete question and create a new one. I deleted old one and created new one after trying your input. But that did not work out. – cool_stuff_coming Apr 22 '21 at 10:12
  • @KamilCuk... i tried the link that you have provided, but using # and | in sed is also not working. – cool_stuff_coming Apr 22 '21 at 10:18

1 Answers1

2

Used below:

sed -i "0,/^ROOT.*/s|^ROOT.*|ROOT = \"${ppath}"|" webroot
cool_stuff_coming
  • 443
  • 1
  • 6
  • 19