Script redirection Output "error, correct"--parsing syntax used in service scripts

Source: Internet
Author: User

<1>

>&2 that is 1>&2 the output to the same standard error , before the standard output is redirected to a log file if a standard error is defined
such as: LS 2>a1 >&2 (equivalent to LS >a1 2>&1)
REDIRECT standard output and standard error to A1, no information is visible on the terminal.

First case: Standard correct output ( with >&2) = = = =

[[email protected] test]# Ls 2>a2 >&2            equals     #ls  >a2

[[email protected] test]# ls
A1 A2 Core txt
[[email protected] test]# Cat A2//ls output is the standard correct output, (2>a2) If there is a standard error to redirect to a log file before, then the standard output is redirected to this log file ( >&2)
A1
A2
Core
Txt

--------------------------------------------------------------------------------------------------------------- -------------

Second case: Standard correct output ( no >&2) = = = "

[[email protected] test]# ls 2>a3
A1 A2 A3 Core txt
[[email protected] test]# ls
A1 A2 A3 Core txt
[email protected] test]# cat A3

--------------------------------------------------------------------------------------------------------------- -------------

Third case: standard error output ( with >&2) = = = "

[[email protected] test]# ls
Core txt
[[email protected] test]# ls sdfji 2>a1 >&2
[[email protected] test]# ls
A1 Core TXT
[email protected] test]# Cat A1
Ls:cannot access sdfji:no such file or directory//2 is the standard error output.

Fourth case:

[[email protected] test]# ls >a2 >&2 //have >&2 The correct output is not redirected to file.
A1 A2 Core txt

Fifth case:

[[email protected] test]# ls &>a2 >&2 //This condition is the same as the 1th case (when the standard error output), (when the standard correct output) Same as the fourth case.
[[email protected] test]# ls
A1 A2 Core txt
[email protected] test]# Cat A2
A1
A2
Core
Txt

--------------------------------------------------------------------------------------------------------------- -------------

Summary: Plus >&2 indicates that if " standard error redirect " to a log file before, " standard correct output " is also redirected to this log file ;          If " standard redirect correctly " to a file is not redirected to this log file,"standard correct output" will output normally. That is, it was wrong, and now It is correctly recorded in it, before it is correct, and now it is output correctly.

Please refer to the next service XX status for the code example.

Script redirection Output "error, correct"--parsing syntax used in service scripts

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.