Just wondering if anyone can explain why this works:

echo `cat <<EOF

but this doesn't:

echo <<EOF

(the second snippet doesn't echo anything to stdout.)


Because echo never reads from stdIn. Try this:

echo foo bar | echo

however cat does, if and only if it haves no files in it's args:

echo foo bar | cat

your first example is inserting the result of ... as the argument of echo. your second example is feeding the HEREDOC to echo, and thus ignored.

also, your first example is not protecting the argument to echo, which means the shell will expand it AGAIN after passing it to echo.

Consider a harmuful character as bang, This does not work:

echo `cat <<EOF

This does:

echo "`cat <<EOF
| improve this answer | |

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