繁体   English   中英

如何通过ssh命令行转义远程命令的引号

[英]How to escape quotes for remote command via ssh command line

我在远程服务器上发出以下命令时遇到问题。 | awk'{print $ 1}'似乎对输出没有任何影响。 我错误地转义了引号字符吗? 更糟糕的是,这两个命令实际上是通过python脚本提交的...因此让逃避变得更加混乱......

在本地服务器上:

ssh remote.server.com "find /root/directory -type f -exec md5sum {} + | awk '{print $1}'"

在远程服务器上:

find /root/directory -type f -exec md5sum {} + | awk '{print $1}' 

我们问shellcheck

In yourscript line 1:
ssh remote.server.com "[...] | awk '{print $1}'"
                                           ^-- SC2029: Note that, unescaped, this
                                                       expands on the client side

你去吧 你可以用反斜杠来逃避它。

您可以将$1转义为\\$1或在本地运行awk:

ssh remote.server.com "find /root/directory -type f -exec md5sum {} +" | awk '{print $1}'

结果应该是一样的。

暂无
暂无

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

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