Exp*_*ing 6 linux bash shell ksh
我已经在stackoverflow和其他关于2>&1的使用的来源中检查了几个相关帖子.
不幸的是到目前为止还没有彻底解决它.
我知道2是stderr,1是stdout,我们正在与2>&1结合.
但我的问题是:有什么区别:
1. mycommand > /dev/null
2. mycommand 2> /dev/null
3. mycommand > /dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)
我刚在想:
相关帖子:
cha*_*aos 13
看到这个:
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非常有用.(见这个答案)