Besides of opening a file using vim and emacs, there is another single way to write some characters into one file.

Here (aka here-document, here-text, heredoc, hereis, here-string or here-script) is a file literal or input stream literal: it is a section of a source code file that is treated as if it were a separate file. The term is also used for a form of multiline string literals that use similar syntax, preserving line breaks and other whitespace (including indentation) in the text.

Here are some sample:

Basically, you can write as follow

$ cat << delimiting_identifier
... your text here
... your text here another line
... delimiting_identifier
your text here
your text here another line

you can replace "cat" using tr, read or something else, you can also replace delimiting_identifier using other word.

By default, behavior is largely identical to the contents of double quotes: variables are interpolated, commands in backticks are evaluated, etc.

$ cat << delimiting_identifier
... $(whoami)
... delimiting_identifier

To prevent this replacement, we can write as follow:

$ cat << 'delimiting_identifier'
... $(whoami)
... delimiting_identifier

It is a very important feature for us.

We can easily generate some fies in script, and write multiline lines to this file.

Categories: Code


Ideals are like the stars: we never reach them, but like the mariners of the sea, we chart our course by them.

1 Comment

xqiushi · June 8, 2017 at 18:04

Google Chrome 58.0.3029.81 Google Chrome 58.0.3029.81 Windows 8.1 x64 Edition Windows 8.1 x64 Edition


Leave a Reply to xqiushi Cancel reply

Your email address will not be published.