Using a here document in a shell script
This doc is kind of an add-on to
Using a here document in a perl script
which is similar, so you may want to have a look at that, too. The point of
this doc is to just show an example of a here doc in a shell script. Also,
in the example below, I use a dash (-) between the << and EO. This makes the script
ignore any tabs within which can be handy if one is indenting for something such
as if statements.
mail -s "test of here document" $1 <<-EOF
This is the body of the message. I'd like it to be indented in
the original script, to make it easier to read. Normally when I do that
it likewise inserts those indents into the email message, such that it
looks odd to the receiver. But in this case the dash above prevents that.
This is the second paragraph, even though it's only one, well perhaps two
sentences. In either case, it's shorter than the first paragraph. But it has
two 2-space tabs in front of it. But like the first paragraph, the tabs will
not be in the email message this script produces.
This last paragraph has no leading tabs. As with the other paragraphs, leading
tabs don't matter. When the message is received, all three paragraphs will line
up on the left margin.