2013-03-25 160 views
2

我寫了一個bash腳本,應該可以從網上安裝。它應該在運行時從用戶那裏獲得輸入。 以下是我如何做到的,但它直接終止應用程序而不提示用戶輸入信息。運行bash腳本捲曲從網絡

curl www.test.com/script.sh | bash 

我在某處讀到stdin是通過bash連接的,這就是爲什麼它不會提示任何東西。

任何幫助將是偉大的。

謝謝你們

回答

6

使用process substitution

bash <(curl www.test.com/script.sh) 
+0

該死的,這是整潔。 – Faiz 2013-03-25 00:46:20

0

嘗試

bash -c '`curl www.test.com/script.sh`' 

雖然這會出現問題,如果腳本中有單引號。

如果做不到這一點,做的兩個步驟:

curl -o /tmp/script.sh www.test.com/script.sh 
bash /tmp/script.sh 

您可以保存腳本您想要的位置,併爲更好的安全性等,你可能想使用tmpfile或東西,但運行腳本直客無論如何,網絡聽起來不像高安全性。

+0

''bash的「'捲曲www.test.com/script。即使沒有單引號,sh''''也不起作用。 – pynexj 2013-03-25 01:41:01

+0

糟糕,我忘了'-c'標誌。更新。 – lxop 2013-03-27 18:55:37

0

你可以嘗試:

bash -c "$(curl -s www.test.com/script.sh)" 

從bash的手冊頁,

-c string If the -c option is present, then commands are read from string. 
      If there are arguments after the string, they are 
      assigned to the positional parameters, starting with $0. 
+0

這隻適用於短於系統最大允許命令行的腳本。 POSIX只保證這個數字大於4096,所以如果你的腳本比較長,這是不可移植的。 – 2013-03-25 00:46:35