我已经在 stackoverflow 和其他来源中检查了几个关于此的相关帖子,了解 2>&1 的使用。
不幸的是,到目前为止我还没有完全理解它。
我知道 2 是标准错误,1 是标准输出,我们正在结合 2>&1。
但我的问题是:
1. mycommand > /dev/null
2. mycommand 2> /dev/null
3. mycommand > /dev/null 2>&1
我在想:
- 将 stdout 和 stderr 重定向到/dev/null
- 将 stderr 重定向到/dev/null
- 将 stdout 和 stderr 重定向到/dev/null
相关帖子:
最佳答案
看这个:
mycommand >/dev/null
它会将 mycommand 的 channel 1(即标准输出)重定向到/dev/null
mycommand 2>/dev/null
它会将 channel 2(即 stderr)重定向到/dev/null
mycommand >/dev/null 2>&1
它将 channel 1 重定向到/dev/null,然后将 channel 2 (stderr) 绑定(bind)到 channel 1 (stdout)。两者都将进入/dev/null
还有一个(刚刚完成)
mycommand 2>&1 >/dev/null
In this second case, I bind (the child's) stderr to stdout (of the parent) and then I find the child's stdout to /dev/null. The result is that you now get the child's stderr output on stdout and the stdout goes to the file. This is useful for processing stderr in a pipe, for example. (see this answer)
关于linux - 混淆输出重定向到 2>&1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20494015/