Cat<<eof in the shell (here document)

Source: Internet
Author: User

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)

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.