2014-06-30 101 views
3

我在遠程服務器上發出以下命令時遇到問題。 | awk'{print $ 1}'似乎對輸出沒有任何影響。我錯誤地轉義引號字符?更糟糕的是,這兩個命令實際上是通過一個python腳本提交......從而使逃生只是更加混亂......如何通過ssh命令行遠程命令的引號逃脫

在本地服務器:

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

在遠程服務器:

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

回答

6

讓我們問shellcheck

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

你去那裏。你可以用反斜槓來轉義它。

3

您可以逃脫$1\$1或者AWK本地運行:

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

結果應該是一樣的。

+0

謝謝!你是一個野獸! – user3388884