我在stackoverflow和其他有关2>&1用法的资料中检查了几个相关的帖子。
不幸的是,到目前为止,我还没有完全了解它。
我知道2是stderr,1是stdout,我们将2>&1组合在一起。
但是我的问题是:
1. mycommand > /dev/null
2. mycommand 2> /dev/null
3. mycommand > /dev/null 2>&1
我刚在想:
相关职位:
看到这个:
mycommand > /dev/null
它将mycommand的通道1(即stdout)重定向到/ dev / null
mycommand 2> /dev/null
它将频道2(stderr)重定向到/ dev / null
mycommand > /dev/null 2>&1
它将通道1重定向到/ dev / null,然后将通道2(stderr)绑定到通道1(stdout)。两者都将进入/ dev / null
还有另一个(只是要完成)
mycommand 2>&1 > /dev/null
在第二种情况下,我将(孩子的)stderr绑定到(父母的)stdout,然后找到孩子的stdout到/ dev / null。结果是您现在在stdout上获得了孩子的stderr输出,并且stdout进入了文件。例如,这对于在管道中处理stderr很有用。(请参阅此答案)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句