<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