0

I have a file having some text like:

ipaddress="127.0.0.1"

I have to replace the 127.0.0.1 with a variable say $ip_add, where $ip_add=127.0.0.2 the following sed command is not working

sed -i 's/127.0.0.1/$ip_add/' conf.py

when i run this command the text is file like this

ipaddress="$ip_address"

Please help. thanks in advance

1 Answers1

0

This is how you use variables in quotes

#!/bin/bash
export ip_add=192.168.1.10
echo "This is my ip: '$ip_add'"

Another way is like this

#!/bin/bash
export ip_add=192.168.1.10
echo "This is my ip: ${ip_add}"

when you use the single quotes in the second example, the variable wont substitute properly.

Toasty140
  • 131