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.

7
  • Conveniently, I was just trying to figure out how to use it with a stdout redirection last night and couldn't get it. I kept trying to do EOF > outfile.txt at the end, which doesn't work well Oct 8, 2010 at 14:07
  • 2
    POSIX 2008 > Shell Command Language > Redirection > Here-Document
    – jw013
    Mar 23, 2012 at 5:47
  • 1
    man bash and look for << (in my man viewer, the search command is the / character, so /<< gets me to the right section).
    – jfg956
    Mar 23, 2012 at 8:33
  • For an experiment, you should have tried 'cat <<HERE'. echo doesn't read stdin.
    – XTL
    Mar 23, 2012 at 15:02
  • possible duplicate of How does << work and what is it called? Mar 23, 2012 at 18:55

3 Answers 3

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
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."

You must log in to answer this question.

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