Where do people use the "Here document" on UNIX systems?

Where is it used in reality?

  • People use it in a number of ways. What's your question, really? I'm voting to close as too broad.
    – muru
    Sep 28, 2015 at 6:54

3 Answers 3


ftp and the like are good examples.

For instance, if you want to stablish an ftp connection and retrieve some files you can create a script that does something like:

lftp machine -uUser,Passwd << END
    cd your_dir
    get your_file

You have automated files retrieval with a "Here document"


It is often used for multi line output.


echo "first line" >output
echo "second line" >>output
echo "third line" >>output


cat >output <<"END"
first line
second line
third line

Both should do exactly the same, but especially with long text the second version is easier.


A here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor.

A more detailed example and explanation can be found here:

Here Documents

A grep command example for "Here document":

grep this <<"END"
> this is an example
> with example
this is an example
  • 1
    And this is reality for whom?
    – Anthon
    Sep 28, 2015 at 7:24
  • Just another "Here document" example using grep command.
    – snoop
    Sep 28, 2015 at 7:48
  • 1
    But the OP is not asking for that, the question is "where is this used in reality".
    – Anthon
    Sep 28, 2015 at 8:18
  • Added references for explanation.
    – snoop
    Sep 28, 2015 at 13:26

Not the answer you're looking for? Browse other questions tagged .