bash 管道到多个文件,但不是标准输出

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15265228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:46:07  来源:igfitidea点击:

Pipe to multiple files, but not stdout

bashstdouttee

提问by Steven Penny

I want to pipe stdout to multiple files, but keep stdout itself quiet. teeis close but it prints to both the files and stdout

我想将标准输出通过管道传输到多个文件,但要保持标准输出本身安静。tee已关闭,但它会同时打印到文件和标准输出

$ echo 'hello world' | tee aa bb cc
hello world

This works but I would prefer something simpler if possible

这有效,但如果可能的话,我更喜欢更简单的东西

$ echo 'hello world' | tee aa bb cc >/dev/null

回答by anishsane

You can simply use:

您可以简单地使用:

echo 'hello world' | tee aa bb > cc 

回答by Jirka

You can also close tee stdout output by writing to /dev/full

您还可以通过写入来关闭 tee stdout 输出 /dev/full

echo 'hello world' | tee aa bb cc >/dev/full

or by closing stdout.

或关闭标准输出。

echo 'hello world' | tee aa bb cc >&-

Be however aware that you will get either tee: standard output: No space left on deviceor tee: standard output: Bad file descriptorwarnings.

但是请注意,您将收到tee: standard output: No space left on devicetee: standard output: Bad file descriptor警告。