我在远程服务器上发出以下命令时遇到问题。 | 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}'
结果应该是一样的。