简体   繁体   English

sed命令无法通过SSH使用

[英]Sed command not working through SSH

Consider the following command: 考虑以下命令:

ssh MACHINE sed -i 's#\[ "\$JBOSS_MODE" = "standalone" \]#\[ "\$JBOSS_MODE" = "sim_standalone" \]#' /tmp/sim-wildfly

When I run this command from the command line, I get this error: 当我从命令行运行此命令时,出现以下错误:

sed: -e expression #1, char 3: unterminated `s' command

However, when I SSH into that particular machine first, and then run the sed part of the command, it works fine: 但是,当我先通过SSH进入该特定计算机,然后运行命令的sed部分时,它可以正常运行:

> ssh MACHINE
> sed -i 's#\[ "\$JBOSS_MODE" = "standalone" \]#\[ "\$JBOSS_MODE" = "sim_standalone" \]#' /tmp/sim-wildfly

Any idea why this would happen? 知道为什么会这样吗?

EDIT: I believe it has something to do with how I'm escaping characters, because I just tried simple test replacement with no escaped characters and it worked fine. 编辑:我认为这与我转义字符有关,因为我只是尝试了简单的测试替换而没有转义字符,并且效果很好。 I tried double-escaping, but that didn't work either. 我尝试了两次转义,但这也不起作用。

Try ssh with here-doc to avoid crazy escaping: 尝试使用带有此处文档的ssh以避免疯狂转义:

ssh -t -t MACHINE <<'EOF'
sed -i 's#\[ "\$JBOSS_MODE" = "standalone" \]#\[ "\$JBOSS_MODE" = "sim_standalone" \]#' /tmp/sim-wildfly
exit
EOF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM