Landlord these days encountered a relatively novel usage is hereby recorded.
To print multiple lines of files to the screen with cat.
Let's feel it first and then do a detailed introduction
Program:
#! /bin/bash
cat << EOF
Super
Very good!!
Eof
Effect
One, Cat and EOF
The cat command is a text output command under Linux, usually used to view the contents of a file;
EOF is "End of File", which represents a text terminator.
By combining these two identities, you can avoid the use of multiple lines of ECHO commands and implement the results of multiple-line output.
Second, the use
See example is the quickest familiar method:
# cat << EOF > test.sh
> #!/bin/bash
> #you Shell script writes here.
> EOF
Results:
Reference # Cat Test.sh
#!/bin/bash
#you Shell script writes here.
As you can see, the content of test.sh is what cat generates.
Third, other wording
1. Append files
# cat << EOF >> test.sh
2, another way of writing
# cat > Test.sh << EOF
3, EOF is only logo, not fixed
# cat << HHH > Iii.txt
> SDLKFJKSL
> Sdkjflk
> ASDLFJ
> HHH
The "HHH" here replaces the "EOF" function. The results are the same.
Reference # Cat Iii.txt
Sdlkfjksl
Sdkjflk
Asdlfj
4, not in the script
If it's not in the script, we can use ctrl-d to output EOF's identity
# cat > Iii.txt
Skldjfklj
Sdkfjkl
Kljkljklj
Kljlk
Ctrl-d
Results:
Reference # Cat Iii.txt
Skldjfklj
Sdkfjkl
Kljkljklj
Kljlk
※ for the meaning of ">", ">>", "<", "<<" and so on, please check the introduction of Bash yourself.