0

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 '15 at 06:54

3 Answers3

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"

YoMismo
  • 4,015
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.

michas
  • 21,510
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
snoop
  • 324
  • 2
  • 14