sed over ssh并没有逃避反斜杠

时间:2016-06-01 13:13:29

标签: linux bash ssh sed

我试图在" rezhome"之前添加一行。在文件中,如下所示:

...
app3-reservation, \
app4-reservation, \
app5-reservation, \
rezhome

当我使用以下命令在本地运行时,它可以正常工作。

sed -i 's/rezhome/app5-reservation, \\\n&/' grouphost.cfg

但是使用ssh反斜杠并没有转义,我得到了结果

ssh localhost "sed -i 's/rezhome/app5-reservation, \\\n&/' /path/grouphost.cfg"

...
app3-reservation, \
app4-reservation, \
app5-reservation, \nrezhome

请帮忙吗?

1 个答案:

答案 0 :(得分:6)

\sed同时处理ssh,因此您需要进一步转义它们以便同时使用它们。尝试:

 ssh localhost "sed -i 's/rezhome/app5-reservation, \\\\\n&/' /path/grouphost.cfg"