在 bash 中使用兩個指令讀取相同的標準輸入

在 bash 中使用兩個指令讀取相同的標準輸入

我想在 bash 中將輸出傳輸到兩個單獨的命令 <2,3> 。這樣做的最佳方法是什麼?目前,我有以下腳本:

command source > output
command2 output &
command3 output &

輸出檔約為 100G,次優方法是分別透過管道傳輸到指令 2 和 3。我認為可以做得更有效。

答案1

在bash中:command source | tee >(command2) >(command3)

堆疊溢位問題。我還沒有嘗試過使用巨大的輸出。

答案2

其他答案介紹了這個概念。下面是一個實際的示範:

$ echo "Leeroy Jenkins" | tee >(md5sum > out1) >(sha1sum > out2) > out3

$ cat out1
11e001d91e4badcff8fe22aea05a7458  -

$ echo "Leeroy Jenkins" | md5sum
11e001d91e4badcff8fe22aea05a7458  -

$ cat out2
5ed25619ce04b421fab94f57438d6502c66851c1  -

$ echo "Leeroy Jenkins" | sha1sum
5ed25619ce04b421fab94f57438d6502c66851c1  -

$ cat out3
Leeroy Jenkins

當然你可以> /dev/null代替out3。

相關內容