
我正在使用 bash shell 並試圖找出編寫以下內容的正確方法:
ssh mysuer@remotehost 'echo "update user set url = \'localhost\' where url = \'mydomain.com\';" >> /tmp/db.sql'
到目前為止,上述方法還不起作用。
輸入後,下面一行是 a ,>
就好像它期望我在某處關閉未平倉報價一樣。我需要做什麼才能做到這一點
update user set url = 'localhost' where url = 'mydomain.com';
是否輸出到遠端文件?
答案1
單引號無法轉義,但您可以結束現有單引號,列印撇號 ( \'
) 並開啟新單引號。
這是正確的語法:
ssh user@host 'echo "update user set url = '\''localhost'\'' where url = '\''mydomain.com'\'';" >> /tmp/db.sql'
答案2
如果您從 mysql 語句內的單引號中刪除反斜杠,它應該可以工作:
ssh mysuer@remotehost 'echo "update user set url = 'localhost' where url = 'mydomain.com';" >> /tmp/db.sql'