嘿傢伙我試圖集成一些PY到我的shell腳本和運行跨越 以下錯誤,我雖然報價應引用我的變量,但它看起來像它的 沒有按照我的預期做,有人可以幫我解決這個問題嗎?BASH程序中的Python文件測試行失敗,語法錯誤
#!/bin/bash
host='[email protected]'
path='/home/user/file'
python -c "return subprocess.call(['ssh', '$host', 'test -e ' + pipes.quote($path)]) == 0"
File "<string>", line 1
return subprocess.call(['ssh', "[email protected]", 'test -e ' + pipes.quote(/home/jdaniel/sent)]) == 0
^
SyntaxError: invalid syntax
文件「」,1個線語法錯誤:「迴歸」之外的功能? –
ehime
只是想學習一些PY來補充我的bash,加上bash並沒有真正的測試其他服務器上是否存在文件的方法。我想我可以使用rsync,但它聽起來並不像我想的那樣有趣。 – ehime
是啊,因爲你不能有一個函數外的返回......你有一個返回作爲程序中的唯一行......但這是一個不同的問題......但只是從你的Python代碼中刪除單詞「返回」。 ..你所做的就是從python裏面調用ssh程序......這與100%是一樣的,就像你從bash afaik調用它一樣...... –