Here document usage for Linux shell (cat << EOF)
What is here Documenthere Document is a special redirection method in the Linux Shell, and its basic form is as follows CMD << delimiter here document Contentdelimiter
its role is to pass the contents of the two delimiter (Here Document content section) to cmd as input parameters.
For example, if you enter Cat << EOF in the terminal, you will be prompted to continue with the input, enter multiple lines of information and then enter EOF, and the information entered in the middle will be displayed on the screen. as follows: [email protected]:~$ cat << eof> first line> Second line> third line eof> Eoffirst linesec Ond linethird line EOF Note: > This symbol is the identifier for the terminal to generate prompt input information here to note a few eof is just a logo, you can replace any legal character as the end of the delimiter must be shelf write, The preceding delimiter cannot have any characters (including spaces) as the beginning of the delimiter before and after the space is omitted. Here document can be used not only on the terminal, but also in shell files. For example, the following here.sh file cat << eof > Output.shecho "Hello" echo "World" EOF uses SH here.sh to run this script file and will get output.sh this new file, The contents are as follows echo "Hello" echo "World" the variants of the here document delimiter and variables in the contents of here document can include not only ordinary characters, but also the use of variables inside, For example, change the above here.sh to cat << EOF > Output.shecho "This is output" echo $1eof use sh here.sh heredocument to run the script to get output The contents of the. Sh echo "This is output" echo heredocument here is expanded to be the parameter of the script heredocument but sometimes do not want to expand this variable, can be done by the beginning of the Delimiter "To implement, for example, change the above here.sh to cat << EOF > output.sh #注意引号echo" Hello "echo" World " EOF gets the output.sh content of echo "This is output" echo $1<< to <<-here DAnother use of ocument is to turn ' << ' into ' <<-'. The only change in the use of <<-is that the tab (tab) in front of each line of the content section of the here document will be deleted, which is used to indent the Content section for writing here document so that you can easily read the code.
Cat<<eof (here document) in the shell (go)