Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
    
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). –  jfgagne 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

3 Answers 3

up vote 17 down vote accepted

That's called a "Here document".

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

share|improve this answer

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

$ tac << EOT
> 123
> 456
> EOT
456
123
share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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