Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

the "cmd <<EOL ..\n..\n EOL" part has been mystical to me for ages, especially as I didn't know what to google to find out. I recently learned it was called a "Here Document". http://en.wikipedia.org/wiki/Here_document

For extra credit, try using a "Here Document" as input for 'echo' and 'cat'. Explain the results.



`man bash` , search for "<<" see the "Here Strings" section.

You can also search https://www.google.com/search?q=bash and follow links to "Documentation"

    xargs echo <<EOL  
    > line 1
    > line 2  
    > EOL
    line 1 line 2

    $ cat <<EOL
    > line 1
    > line 2 
    > EOL
    line 1
    line 2
line-terminators get eaten by xargs


What is so mystifying about this?

Doing this:

"cat << EOL

line one

line two

EOL"

Would be the same as this:

"cat < file"

That is if 'file' contained this:

"line one

line two"

This doesn't work with the echo command because it does not use stdin like cat does.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: