1. three standard operating system conventions: stdinstdoutstderr corresponds to 0, 1, 2. in shell scripts, output redirection is often involved: for example. myscriptoutpufile, where file is equivalent to 1 file, that is, the output is redirected to the file. Corresponding, 21, right? The standard error is redirected to the standard output, and the file is used to set the standard output.
1. three standard operating system conventions: stdin stdout stderr corresponds to 0, 1, 2, respectively. in shell scripts, output redirection is often involved: for example. /myscript outpufile, where file is equivalent to 1 file, that is, the output is redirected to the file. Corresponding, 21, right? The standard error is redirected to the standard output, and the file is used to set the standard output.
1. Three standards
According to the operating system conventions, stdin stdout stderr corresponds to 0, 1, 2, respectively.
In shell scripts, output redirection is often involved:
For example,./myscript> outpufile, where> file is equivalent to 1> file, which means the output is redirected to the file.
Corresponding, 2> & 1, right? The standard error is redirected to the standard output.
&> File redirects standard output and standard errors to file
2. Common examples
N> & m indicates that file descriptor n is a copy of output file descriptor m. The advantage of this is that sometimes you may easily generate useless information when searching for files, for example, 2>/dev/null is used to not display standard error output; in addition, when you run some commands, the error information may be very important, so that you can check what is wrong, such as: 2> & 1
For example:
Note: For ease of understanding, you must set up an environment for normal output and error output to run the grep da * command. Then, use the following command to generate three files:
Grep da *> greplog1
Grep da *> greplog2 1> & 2
Grep da *> greplog3 2> & 1 // grep da * 2> greplog4 1> & 2 returns the same result
# Check greplog1 and you will find that only the normal output content is in it.
# Check greplog2 and you will find nothing in it.
# Check greplog3 and you will find both the normal output content and the error output content.