I am trying to set an IP in a file with sed. I am running this command
sed -i 's:$dbserver='':$dbserver='10.0.0.2':' t.conf
but when I look in t.conf the line is
$dbserver=10.0.0.2''
Anyone know why the two single quotes are appearing at the end of the line?
I am runn开发者_如何学JAVAing Debian Linux
You need to enclose the second sed
argument in double quotes:
sed -i "s:$dbserver='':$dbserver='10.0.0.2':" t.conf
This way $dbserver
will be substituted with its value before being passed to sed
, and the single quotes won't need escaping.
If you want $dbserver
to appear literally in the conf file, preceed the dollar signs with a backslash.
精彩评论