Reprinted from: http://dos2unix.cn/link/480
1. Standard input stdin file descriptor is 0, standard output stdout file descriptor is 1, standard error stderr file descriptor is 2
2./dev/null empty equipment, equivalent to garbage bin
3. REDIRECT Symbol:>
3. The difference between 2>1 and 2>&1
- 2>1, redirect standard error stderr to file 1
- 2>&1, redirect standard error stderr to standard output stdout
4. For example:
Suppose there is a script test.sh, the content is as follows, T is a non-existent command, execute the script to test below.
Shell
The standard output is redirected to log, and the error message is output to the terminal, as follows:
Shell
|
#./test.sh > Log. /Test. SH: Line 1: t: command not Found # Cat LogThu Oct : £º --CST |
Delete log file, re-execute, this time the standard output is directed to log, error message directed to the file 1
Shell
|
#./test.sh > Log 2>1## Cat LogThu Oct : £º- CST # cat 1. /Test. SH: Line 1: t: command not Found # |
REDIRECT standard output to log file, redirect standard error to standard output, i.e. redirect error message and output information to log
Shell
|
#./test.sh > Log 2>&1## Cat Log. /Test. SH: Line 1: t: command not found Thu Oct:: +- CST # |
REDIRECT error messages to an empty device
Shell
|
#./test.sh 2>/dev/null Thu Oct :£ º CST # |
REDIRECT standard output to an empty device
Shell
|
#./test.sh >/dev/null . /Test. SH: Line 1: t: command not Found # |
Full redirect of standard output and standard error to empty device
Shell
|
#./test.sh >/dev/null 2>&1 # |
Full redirect of standard output and standard error to empty device
Shell
|
#./test.sh >/dev/null 2>&1 # |
Shell's >/dev/null, 2>&1, 2>1