Cat command and EOF ID output Shell to file

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.