
我做了一個 bash 函數來美化svn
輸出,這個函數顯示每次提交只記錄一行,太棒了!我喜歡它,但如果我將它與管道一起使用,它就不起作用。您可以在以下位置找到它:github svn-美化
$ svn -log -l 2
r22 fabio 2014-03-27 12:38:10 +0100 (gio, 27 mar 2014) 1 line Some comments
r23 fabio 2014-03-27 13:35:17 +0100 (gio, 27 mar 2014) 1 line Some comments
如果我可以將它與 一起使用,那就太好了| grep
。
答案1
你有這個:
if [ "$SVN_COLOR" != "always" ] && (
[ $NOCOL = 1 ] || [ "$SVN_COLOR" = "never" ] || [ ! -t 1 ]
)
這是[ ! -t 1 ]
導致您的函數返回過早的測試。當您將函數透過管道傳輸到管道時,stdout(檔案描述符1
)是不是一個終端。
答案2
這絕對不是一般的 bash-function-with-pipes-問題。
~$ x() { ls "$@" ; }
~$ x / | cat -n | head
1 bin
2 boot
3 dev
4 etc
5 home
6 initrd.img
7 initrd.img.old
8 lib
9 lib32
10 lib64
……沒有專門用於程式碼審查的 Stackexchange 網站嗎?或許去那裡問問?