![](/img/trans.png)
[英]How can I pipe a bash variable into a GREP regex in the following command?
[英]Reuse a command to pipe in bash
我使用以下內容來縮進配置腳本的輸出:
./configure | sed "s/^/ /"
現在我想重用管道后面的部分,所以我不必寫
./configure | sed "s/^/ /"
make | sed "s/^/ /"
make install | sed "s/^/ /"
我試圖將sed
放在這樣的變量中:
indent=sed "s/^/ /"
然后做
./configure | indent
但這不起作用 - 我怎樣才能做到這一點?
使用 BASH 數組來保存 sed 命令:
indent=(sed "s/^/ /")
然后使用:
./configure | "${indent[@]}"
make | "${indent[@]}"
make install | "${indent[@]}"
或者為此 sed 命令使用一個函數:
indent() { sed "s/^/ /"; }
然后使用:
./configure | indent
make | indent
make install | indent
為什么不讓它成為別名?
alias indent="sed 's/^/ /'"
嘗試這個:
(./configure; make; make install) | sed "s/^/ /"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.