command > file redirects the output to file.
Command < file redirects the input to file.
command >> file redirects the output to file in an append manner.
n > file redirects the file descriptor n files to filename.
n >> files redirect files with file descriptor N as an append to file.
N >& m merges the output file m and N.
N <& m merges the input file m and N.
<< tag will start to tag the contents of tags between tag and end tag as input.
Note: File descriptor 0 is typically standard input (STDIN), 1 is standard output (STDOUT), and 2 is the standard error output (STDERR).
Output redirection
- < overwrites the contents of the file
- << does not overwrite the contents of the file, appending the output to the end of the file
Execute command and then save the output to File1 (overwrite file1 original content)
Command > File1
Executes command, then appends the output to the end of the File1 file (without overwriting the original contents of File1)
Command >> File1
Input redirect
Get content from File1
Command < File1
Here Document
redirect input to an interactive Shell script or program
Command << delimiter
Document
Dilimiter
Note:
1, the end of the delimiter must be shelf write, the front cannot have any characters, the back can not have any characters, including spaces and tab indentation
2, the beginning of the delimiter before and after the space will be ignored
WC -L << EOF Welcome to learn the Shell scripting language happy every day EOF
/dev/null file
If you want to execute a command but do not want the output to be displayed on the screen, you can redirect the output to/dev/null
Command >/dev/null
The Shell file contains
The Shell can also contain external scripts. This makes it easy to encapsulate some common code as a standalone file
. FileName
Or
Source FileName
Shell Script Learning Note 10: Shell input and output redirection