Linux_cat_ uses cat and terminator to output multiple lines of text __linux

Source: Internet
Author: User

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.















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.