我已经知道如何使用tee
和进程替换来将输出发送到各种命令,以及stdout,例如
command0 | tee >(command1) >(command2)
使用上面的行,stdout将由来自command0
,command1
和command2
的交错行组成。
有没有办法防止tee写入stdout,而不删除它管道的任何命令的输出?那么对于上面的例子,stdout只有command1
和command2
的输出?与没有标准输出的tee
ing相关的大多数答案只是直接写入文件,并建议使用这样的东西:
command0 | tee file1 file2 >/dev/null
但是使用进程替换,也会消耗其他命令的所有输出。
command0 | tee >(command1) >(command2) >/dev/null
有没有办法告诉tee
不打印到stdout,或只是直接从tee
消耗输出?
试试这个:
( command0 | tee >(command1 1>&3 ) | command2 ) 3>&1
它将command1的stdout重定向到管道3,以便command2只能看到原始源。最后,您再次将管道3重定向到stdout。
用它来测试它:
( echo test | tee >( sed 's/^/1 /' >&3 ) | sed 's/^/2 /' ) 3>&1
输出是无序的,在我的情况下:
2 test
1 test