6

I've just come across the << command, used like so:

cat > outfile.txt <<EOF
Multi-line content
that will be written to outfile.txt
EOF

Now, I've no idea what this is called, but I'd quite like to know it's name, primarily so I can go and search and find out more about its syntax. Sadly, Googling for "<<" just doesn't work.

echox
  • 18,103
me_and
  • 1,151
  • 1
  • 13
  • 24

3 Answers3

17

That's called a "Here document".

http://en.wikipedia.org/wiki/Here_document

8

It's form of redirection called a here document or heredoc. It redirects the contents of the given in-line document to a command. The document is delimited by the given word (EOT below). Quoting the word or part of the word after << creates a quoted here-document that the shell will not perform expansions in.

$ tac << EOT
> 123
> 456
> EOT
456
123
Kusalananda
  • 333,661
1

In a Unix context it really is known as a "here document." I believe that the "heredoc" construct comes from PHP, Perl, and other scripting languages, and for shell scripting I'd tend to stick with "here document."

Melinda
  • 211