In some cases, we might need to generate a temporary file in the script and then put the file in the directory as the final file. (You can refer to the Ntop.spec file) There are several benefits, one of which is that temporary files are not unique, can be assigned by variables, and can generate different final files based on different judgments, and so on.
I, Cat and EOF
The cat command is a text output command under Linux, usually for viewing the contents of a file;
EOF is "End of File", which represents the text terminator.
Combining these two identities avoids the use of multi-line echo commands and results in multiple lines of output.
Second, use
Looking at examples is the quickest way to get acquainted:
# 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 cat-generated content.
Third, other wording
1. Append files
# cat << EOF >> test.sh
2, in a different way
# cat > Test.sh << EOF
3. EOF is just a sign, not a fixed
# cat << HHH > Iii.txt
> SDLKFJKSL
> Sdkjflk
> ASDLFJ
> HHH
The "HHH" here replaces the "EOF" function. The result is the same.
Reference # Cat Iii.txt
Sdlkfjksl
Sdkjflk
Asdlfj
4, not in the script
If it's not in the script, we can output the EOF ID with ctrl-d
# cat > Iii.txt
Skldjfklj
Sdkfjkl
Kljkljklj
Kljlk
Ctrl-d
Results:
Reference # Cat Iii.txt
Skldjfklj
Sdkfjkl
Kljkljklj
Kljlk himself read This example, wrote a test program to put it together: 1.#test.sh#!/bin/sh
Cat << EOF > Xiaozhao.txt
Hello
Zhao
Xiao
EOF#./TEST.SH generates the Xiaozhao.txt file under the current directory. # Cat Xiaozhao.txt
Hello
Zhao
Xiao 2. Modify test.sh to #!/bin/sh
Cat << EOF
Hello
Zhaoxiao
Eof#./test.shhello
Zhao
Xiao
Cat command and EOF ID output Shell to file