如何從 URL 下載腳本,執行它,并將某些內容通過管道傳輸到其中 - 只需一個命令?
我有一個 shell 腳本,我可以通過管道傳輸東西:
$ echo "Test Data" | do-stuff.sh
腳本移至http://example.com/do-stuff.sh
嘗試做這樣的事情:
$ echo "Test Data" | ( curl -sfL http://example.com/do-stuff.sh | sh )
但它不起作用。資料不會通過管道傳輸到腳本中。
有一種解決方法,但是如何在不創建檔案的情況下用一行來做到這一點?
$ curl -sfL http://example.com/do-stuff.sh > do-stuff.sh
$ chmod x do-stuff.sh
$ echo "Test Data" | do-stuff.sh
$ rm do-stuff.sh
uj5u.com熱心網友回復:
嘗試
echo "Test Data" | sh <(curl -sfL http://example.com/do-stuff.sh)
由于行程替換,這需要在 bash 或 zsh 或 ksh 中運行。
你的不作業的原因是sh行程的標準輸入通道已經被讀取源代碼所消耗,所以你不能將資料輸入它。
行程替換就像一個檔案,因此sh可以從“檔案”中獲取源代碼并仍然從標準輸入讀取資料。
uj5u.com熱心網友回復:
假設與腳本的鏈接包含未經任何轉換的原始資料,那么您可以嘗試這種方法
echo "Test Data" | bash <(wget -O - http://example.com/do-stuff.sh)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/491426.html
上一篇:每次列印列印作業時,如何撰寫Windows10腳本以將計數器增加1?
下一篇:更改awk找到結果的顯示格式
