Shell redirection & amp; & gt; file2 & gt; & amp; 11 & gt;

Source: Internet
Author: User
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.

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.