Output redirection __linux for Linuxshell scripts

Source: Internet
Author: User

Output redirection of the Linuxshell script, which supports input and output redirection in the Linux Shell environment, is represented by symbols < and >. 0, 1, and 2 represent standard input, standard output, and standard error information output, which can be used to specify standard inputs or outputs that require redirection, such as 2>a.txt to output error messages to file A.txt.

Input-output redirection is supported in the Linux Shell environment, represented by symbols < and >. 0, 1, and 2 represent standard input, standard output, and standard error information output, which can be used to specify standard inputs or outputs that require redirection, such as 2>a.txt to output error messages to file A.txt.

In the meantime, redirects can be achieved between these three standard input outputs, such as redirecting error messages to standard output, and can be implemented using 2>&1.

Linux also has a special file/dev/null, it is like a bottomless pit, all redirected to its information will disappear without a trace. This is useful when we can redirect output to/dev/null when we do not need to echo all the information about the program.

If you want normal output and error messages to be displayed, redirect both standard output and standard error to/dev/null, for example:

# ls 1>/dev/null 2>/dev/null

Another approach is to redirect errors to standard output, and then redirect to/dev/null, for example:

# ls >/dev/null 2>&1

Note: The order here cannot be changed, otherwise the desired effect is not achieved, the standard output is redirected to/dev/null first, then the standard error is redirected to standard output, and the standard error is redirected to/dev/null because the standard output has been redirected to/dev/null. So it's all quiet:-)

In addition +:

$make >& Filename.log &

It means redirecting both standard and error outputs, make>out only the standard output is redirected

>log means redirecting standard output to file log

>& log indicates that both standard output and error output are directed to the file log, equivalent to >log 2>&1

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.