【问题标题】:How to escape quotes for remote command via ssh command line如何通过 ssh 命令行转义远程命令的引号
【发布时间】:2014-08-21 07:20:21
【问题描述】:

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

【问题讨论】:

    标签: python linux awk command escaping


    【解决方案1】:

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

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

    结果应该是一样的。

    【讨论】:

    • 谢谢!你是个野兽!
    【解决方案2】:

    我们问shellcheck

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

    给你。你可以用反斜杠转义它。

    【讨论】:

      猜你喜欢
      • 2013-03-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-28
      • 2018-04-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多