Question

i can able to use the below command to change value of target by means of hard coding.

sed -ie s/^target=.*/target=google.com/ url.properties

But if i used variable i am getting error. I dont know how sed commands all working. I only needed to set build system thats it.

url = google.com
sed -ie s/^target=.*/target=$url/ url.properties

the error is sed: -e expression #1, char 25: unterminated `s' command

Was it helpful?

Solution

The problem may be happening because your URL may contain / which bash interprets as sed syntax, so something like https/www.google.com ends up something like :

sed -ie 's/^target=.*/target=https/www.google.com/' url.properties

I will suggest to delimit any special characters to avoid sed to be confused :

url=google.com
url=`echo $url | sed -e "s/\//\\\\\\\\\//g"` # delimits backslash in URL's
sed -ie "s/^target=.*/target=$url/" url.properties

OTHER TIPS

Two problems:

  • You can't have spaces in variable assignments in bash
  • You must quote the sed command (and ideally the url too)

Working example:

url="google.com"
sed -ie "s/^target=.*/target=$url/" url.properties
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top