here document operator
is used in shell scripts.
It tells the shell to take lines from the script as standard input to a command.
The example below shows
a loop (
that prints three nasty form letters with the
Each letter has a different person's name and the current date at the top.
You can put this loop into a
shell script (
or just type it in
at a Bourne shell prompt (
Each line of the loop body starts with a TAB character, which the
operator removes before the printer gets the text:
for person in "Mary Smith" "Doug Jones" "Alison Eddy"
lpr <<- ENDMSG
This is your last notice. Buy me pizza tonight or
else I'll type "rm -r *" when you're not looking.
This is not a joak.
The midnight skulker
This loop runs three
commands; each form letter prints on a
The shell reads the standard input until it finds the
terminator word, which in this case is
The word (
) has to be on a line all by itself.
(Some Bourne shells don't have the
operator to remove
leading TAB characters.
In that case, use
and don't indent the loop body.)
command and output its date;
is replaced with the person's name set at the top of the
The rest of the text is copied as is to the standard input of the