0

I'm trying to change a line of syntax in a config file where the line looks like the following:

host="192.0.2.100"

I'm writing a script that would require input the user to change the ip and keep the same format as above. What I wrote:

#/bin/bash
echo "enter IP"
read inputIP
sed -i /host=/c\host="$inputIP" /path/file.xml

What I get when i run this in file is:

host=192.0.2.100

So the question is how do I run this and not lose the quotes?

Christopher H
  • 368
  • 2
  • 18

1 Answers1

2

Quotes are special for the shell, it removes them in a so called "quote removal" before sending the paramteres to sed. To keep them, escape them by backslashes:

sed -i /host=/c\host=\"$inputIP\" /path/file.xml
choroba
  • 374
  • 1
  • 7