The here document <<

Hello,

I want to know the use of the here document with the << operator.
Tried to go through some books but the concept was not clear.

Please can any1 expalin me this with a simple example.

Thanks,
Rahul.

ftp machine << EOF
cd dirName
put file1
quit
EOF

Above is an example where ftp reads commands till it finds EOF. Inorder for above example to work u have to have .netrc configured ( with out asking for passwd).

2 more examples ..

#!/usr/bin/ksh

tr "[a-z]" "[A-Z]" <<EOF
hello world
EOF

cat > file1 <<EOF
abcdefghijklmanopqr
stuv
wxyz
EOF

cat file1

Can any1 give me any example for writing interactive programs using the here document.

Thanks,
Rahul.

bhargav has already given you three examples of here document usage.

You say you want to write an "interactive" program using a here document? The very nature and purpose of a here document is to take away user interaction and provide automation.

If you have a specific requirement, then please post what it is you're trying to do.

Cheers
ZB

Thanks to all of u,

Now i got the concept of the here document.

The idea is that interactive programs can take input from this here document without waiting for user input.

hi....i understood why the here block is used...but i fail to understand the exact control flow behind it...i mean how does is work and what is the concept behind it? can u kindly throw some light on it? thanks again