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
  • 77,979
  • 13
  • 71
  • 125
Heisenberg
  • 41
  • 2
  • 7

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,443
  • 2
  • 15
  • 23