前言
有時候shell腳本可以放在http頁面上,不用download,可以直接執行。
通常我們可以用curl的方式執行http頁面上的shell腳本。 一般方式是:
curl http://XXX.com/xx/xx.sh | bash
這樣腳本就可以在本地機器上執行了。
帶參
有時也有需要傳入參數的腳本。分為無名參數和具名參數(長選項和短選項)。
無名參
- -s方式
curl -s http://XXX.com/xx/xx.sh | bash -s arg1 arg2
bash <bash <(curl -s http://XXX.com/xx/xx.sh) arg1 arg2
具名參
由於直接調用了bash命令,因此在遠程腳本需要傳遞具名參數時,為了區分是bash命令的參數還是遠程腳本的,可以使用--作為區分,可以理解為分割線,--前面的比如-s屬於bash,后面的-x abc -y xyz屬於遠程腳本的參數
curl -L http://XXX.com/xx/xx.sh | bash -s -- -x abc -y xyz
參考
passing parameters to bash when executing a script fetched by curl
