0

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

Where is it used in reality?

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

3 Answers 3

4

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:

#!/bin/bash
lftp machine -uUser,Passwd << END
    cd your_dir
    get your_file
    bye
END

You have automated files retrieval with a "Here document"

3

It is often used for multi line output.

Compare

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

and

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

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

0

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
> END
this is an example
4
  • 1
    And this is reality for whom?
    – Anthon
    Commented Sep 28, 2015 at 7:24
  • Just another "Here document" example using grep command.
    – snoop
    Commented 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
    Commented Sep 28, 2015 at 8:18
  • Added references for explanation.
    – snoop
    Commented Sep 28, 2015 at 13:26

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