1

I have a replace function like

function replace()
{
sed -i "s#$1#$2#g" $3
}

I am calling the function with these parameters

replace MY_IP $MY_IP /usr/xxx.sh

where $MY_IP is a empty value so sed is giving as sed -i s#MY_IP#/usr/xxx.sh#g

sed no input files

It is not taking the empty value. How to solve this?

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Heisenberg
  • 41
  • 1
  • 2
  • 8

1 Answers1

0

Try quoting $MY_IP.

replace MY_IP "$MY_IP" /usr/xxx.sh

Without the quotes, bash will just skip that argument.

Jon
  • 3,573
  • 2
  • 17
  • 24