Here document not working

Here documents (inline text) are a great way to keep text within a script. But when the document doesn’t work as expected, troubleshooting can be a challenge. Here are some tips: You can prevent shell expansion of variable names and other special characters by placing 2 “” (double quote) characters in front of the ending characters, like this:


cat << ""EOF
some text
some $VAR and special {}:"|)(
EOF

Leading or trailing spaces (or tabs) will cause the shell to ignore the termination word (EOF in the above example). Make sure that the termination word (EOF in this case) starts in column1 and that there is nothing (including whitespace) following the word. When the here document is not terminated, the error messages will be very mysterious. Be sure to look at the first line number mentioned in the shell error message — it will be pointing to the start of the here document.

– See more at: http://serviceitdirect.com/blog/here-document-not-working#sthash.MkA43WT9.dpuf


Tags: