1. The standard input stdin file descriptor is 0, the standard output stdout file descriptor is 1, and the standard error stderr file descriptor is 2
2./dev/null empty device, equivalent to a waste bin
3. Redirection symbols:>
3. 2> 1 and 2> & 1
2> 1. Redirect stderr to file 1.
2> & 1. Redirect stderr to stdout
4. Example:
Suppose there is a script test. Sh with the following content. T is a non-existent command. Execute the script to perform the following test.
# Cat test. Sh
T
Date
The standard output is redirected to log, and the error information is output to the terminal as follows:
#./Test. Sh> log
./Test. sh: Line 1: T: Command not found
# Cat log
Thu Oct 23 22:53:02 CST 2008
Delete the log file and execute it again. This time, the standard output is directed to log, and the error message is directed to file 1.
#./Test. Sh> log 2> 1
#
# Cat log
Thu Oct 23 22:56:20 CST 2008
# Cat 1
./Test. sh: Line 1: T: Command not found
#
Redirects the standard output to the log file and redirects the standard error to the standard output file.
#./Test. Sh> log 2> & 1
#
# Cat log
./Test. sh: Line 1: T: Command not found
Thu Oct 23 22:58:54 CST 2008
#
Redirect error messages to empty Devices
#./Test. Sh 2>/dev/null
Thu Oct 23 23:01:07 CST 2008
#
Redirects the standard output to an empty device.
#./Test. Sh>/dev/null
./Test. sh: Line 1: T: Command not found
Redirect all standard output and errors to empty Devices
#./Test. Sh>/dev/null 2> & 1
#
Redirect all standard output and errors to empty Devices
#./Test. Sh>/dev/null 2> & 1