Bash: what does 2>&1 mean?
This question already has an answer here:
Short: It redirects all output made on STDERR
to STDOUT
.
>
is a redirection operator which will - in the simplest form - redirect all output on STDOUT
into a file.
test.sh > file
If you prefix >
with a number it uses the output from this specific file descriptor - 2 in your example. 1 is stdout, 2 is stderr.
test.sh 2> file.err
will redirect all output from descriptor 2 = stderr to the file.
If you use the special notation &1
instead of a filename, the output is not written to a new file, but instead to the file descriptor with the given number, in this case 1. So:
test.sh 2>&1
redirects from file descriptor 2 (stderr) to file descriptor 1 (stdout)
It's useful if you want to collect all output regardless of where it happened (stdout or stderr) to further processing, like piping into another program.
1 is stdout. 2 is stderr.
2>&1
simply points everything sent to stderr, to stdout instead.
You will get more info about this : here
链接地址: http://www.djcxy.com/p/25588.html上一篇: 在shell脚本中使用2>&1有什么用处
下一篇: Bash:2>&1是什么意思?