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

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

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.

  • 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 – Michael Mrozek Oct 8 '10 at 14:07
  • 2
    POSIX 2008 > Shell Command Language > Redirection > Here-Document – jw013 Mar 23 '12 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 '12 at 8:33
  • For an experiment, you should have tried 'cat <<HERE'. echo doesn't read stdin. – XTL Mar 23 '12 at 15:02
  • possible duplicate of How does << work and what is it called? – Gilles Mar 23 '12 at 18:55

That's called a "Here document".



It's called a here document or heredoc. It redirects the contents to stdin until the keyword is reached.

$ tac << EOT
> 123
> 456

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.