1

I've this code in my script:

no_forward="#net.ipv4.ip_forward=1"
forward="net.ipv4.ip_forward=1"
sed -i 's/$no_forward/$forward/' /etc/sysctl.conf

Based on the man page, -i suffix is not neccesary, but this this use I'll only have the modified file instead both of them (the file modified and the "backup", the previous one).

I need to use that vars, because I needing them after that command so It's useful to have them like that. I guess I should be wrong with the pattern string, but right now I can't find why. Or maybe the problem are the var's strings or their symbols?

Could You help me? I accept other solutions non-sed based if they use bash and don't need special commands, since I'll need to use the script in another computer without installing anymore.

Thanks for reading

Btc Sources
  • 1,912
  • 2
  • 30
  • 58
  • You're right, but since I was thinking in the Sed command, and its pattern, It's possible for someone to go wrong like me and don't think that the problem is not Sed but the syntax used for the string, so hardly would find the solution in the question about quotes looking for Sed, don't you think? Thanks anyway – Btc Sources Dec 27 '14 at 20:14

1 Answers1

1

If you want to be able to use vars in , use double quotes, so :

sed -i "s/$no_forward/$forward/" /etc/sysctl.conf
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223