Here document in Shell

Source: Internet
Author: User
1. Glossary:

The following is Wikipedia's explanation:

Here document[1], also known as heredoc, hereis, here-string or here-script, is a shell (such as SH, CSH, KSh, Bash, powershell, and zsh) in the command line) and define a string method in the program language. It can save the line breaks, dashes, and other blank characters in the text. Some languages allow variable replacement and command replacement in strings.

The most common syntax of the here document is<<Keep up with an identifier, starting from the next line is the text to be referenced, and then close it with the same identifier on a separate line. In Unix shell, the here document is usually used to provide input content for commands.

It seems complicated. The purpose of the here document is to deliver a series of commands that need to be input from the keyboard, simulating manual input, one line at a time to interactive applications or commands.

The format is:

$ tr a-z A-Z <<END_TEXT > one two three > uno dos tres > END_TEXT ONE TWO THREE UNO DOS TRES

END_TEXTUsed as an identifier. It specifies the start and end of the here document,ONE
TWO THREE
AndUNO DOS TRESYes after executiontr.


2. Example

$ cat << EOF > Working dir $PWD > EOF Working dir /home/user

EOF calibrated the start and end of here. This example is equivalent to the input of cat working dir $ PWD, and the output is the same. Do you understand?
Dir $ PWD) is the input of the command (CAT) before the here document!

Note: The here document requires that the input data, especially the string separator "limitstring" used as the end mark, be located at the starting position of a separate line.

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.