Sometimes, when you do shell scripting, you have to call another command that need manual input.
For example, you want to send email from the shell

# mail adiguna@domain.com
To: adiguna@domain.com
From: you@domain.com
Hello!
.
#

You need to type manually the three last lines to send email.

You might ask how to handle this without interaction.
That’s when “here” document comes handy.

You can re-write the script like this
# mail adiguna@domain.com << END
To:
adiguna@domain.com
From: you@adiguna@domain.com
Hello!
.
END

The syntax for here-document is like this:

command << KEYWORD
input1
input2
input3
KEYWORD

I usually use this for mail and Sybase query (isql). For example:

isql -Usa -SSYB -Ppassword -w2000<<-! | egrep -v affected > cgi3.txt
use omcdb
go
select convert(char(10),c.imap_name) as BSC,
convert(char(25),b.imap_name) as SiteName,
convert(char(25),a.imap_name) as CellName,
convert(char(20),a.imap_CGI) as CGI
from BSCCell a,
BSCBTSSiteManager b,
BSCNE c where a.fdn like b.fdn+’.%’ and a.fdn like c.fdn+’.%’  and b.fdn like c.fdn+’.%’
order by c.imap_name
go
quit
!

Or you can also automate your ftp like this :
ftp -in noc4web << end
user anonymous email
prompt off
ascii
mput *.*
bye
end