What is "here" Document in Shell Scripts

The “here” Document

Frequently, a script might call on another script or utility that requires input. To run a script without operator interaction, you must supply that input within your script. The here document provides a means to do this. The syntax for the here document is:

command << Keyword
input1
input2
...
Keyword

For example:

$ cat termheredoc.ksh
#!/bin/ksh

# Script name: termheredoc.ksh

print "Select a terminal type"
cat << ENDINPUT
sun
ansi
wyse50
ENDINPUT

print -n "Which would you prefer? "
read termchoice

print
print "Your choice is terminal type: $termchoice"
$ ./termheredoc.ksh
Select a terminal type
sun
ansi
wyse50
Which would you prefer? sun

Your choice is terminal type: sun
#!/bin/ksh
# This script automates installing the SUNWaudio software package.
#
# The assumption is the answers to the installation questions have
# been documented by performing an actual install. Running the
# script command prior to doing a package installation would
# allow for such documentation.
#
# This software package only asks two questions:
# Do you want to install these conflicting files [y,n,?,q]
# Do you want to continue with the installation of  [y,n,?]
#
# In each case the answer we will give is y for yes. Hence the two
# lines containing y in the here document.

print "About to install the SUNWaudio package."
pkgadd -d spool SUNWaudio << ENDINPUT
y
y
ENDINPUT