bash 在 AIX 中将 STDERR 和 STDOUT 重定向到 /dev/null 失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8560763/
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 01:11:46  来源:igfitidea点击:

Redirecting STDERR & STDOUT to /dev/null in AIX fails

bashredirectaix

提问by Prakash

In AIX, I tried to redirect both STDERR & STDOUT to /dev/null but the redirection doesn't seems to be happening. What might be the problem?

在 AIX 中,我尝试将 STDERR 和 STDOUT 都重定向到 /dev/null,但重定向似乎没有发生。可能是什么问题?

bash-3.2#  /usr/sbin/lsgroup Test-Group | grep kbxb025 > /dev/null 2>&1
Group "Test-Group" does not exist.

回答by thiton

Redirections refer to commands, not whole pipelines. The outputs of grepgo into /dev/null, but not those of lsgroup. To solve these issues, group the pipeline into a subshell:

重定向指的是命令,而不是整个管道。grepgo into的输出/dev/null,但不是lsgroup. 要解决这些问题,请将管道分组为一个子 shell:

( /usr/sbin/lsgroup Test-Group | grep kbxb025; ) > /dev/null 2>&1