1 By default, the standard input is the keyboard, but it can also come from a file or pipe (pipe |).
2) By default, the standard output is a terminal (terminal), but can also be redirected to a file, pipe or post quotation mark (Backquotes ').
3) By default, standard error output to the terminal, but can also be redirected to the file.
4 The standard input, output and error output are respectively expressed as stdin,stdout,stderr, or can be expressed by 0,1,2.
5 in fact, in addition to the above commonly used in the 3 file descriptor, as well as 3~9 can also be used as a file descriptor. 3~9 you can think of a file descriptor that executes somewhere, and is often used as a temporary intermediate descriptor.
Two examples
1 The command 2>errfile:command error is redirected to the file errfile.
2 Command 2>&1 | ...: command errors are redirected to standard output, and errors and standard output are piped to the next command.
3 var= ' command 2>&1 ': Command error redirected to standard output, error and standard output are assigned to Var.
4 command 3>&2 2>&1 1>&3 | ...: Enables the exchange of standard output and error output.
5 var= ' command 3>&2 2>&1 1>&3 ': Exchange of standard output and error output.
6 Command 2>&1 1>&2 | ... (Wrong ...) : This does not enable the exchange of standard output and error output. Since the shell executes commands from left to right, when the 2>&1 is finished, the error output is the same as the standard output, and the execution of 1>&2 is meaningless.
Three "2>&1 file" and "> File 2>&1" differences
1 cat food 2>&1 >file: Error output to terminal, standard output redirected to file files.
2) Cat food >file 2>&1: The standard output is redirected to file files, and the error output is redirected to the same as the standard output, so the error is also printed to file.
Four attention
Normally open files are automatically turned off when the process is rolled out, but a better approach is to close them immediately when you're done with them. Use m<&-to close the input file descriptor m, and m>&-to turn off the output file descriptor m. If you need to turn off standard input with <&-; >&-is used to turn off standard output.
Five simultaneous output to terminal and file copy source Dest | Tee.exe Copyerror.txt
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service