我在远程服务器上发出以下命令时遇到问题。的| 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

你去吧。您可以使用反斜杠将其转义。

关于python - 如何通过 ssh 命令行转义远程命令的引号,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24498277/

10-11 22:29
查看更多