Sending multiple lines of input to a program
Using a ‘here document’ it is possible to send multiple lines of input to a program from a shell script.
A here document uses the << I/O redirector followed by a code. The subsequent lines are redirected to the program until the specified code. The basic syntax is:
program << CoDe
Line of input
More input
extra input
CoDe
The code needs to be something that would not occur in the text. This technique is useful for working with interactive programs like ftp. In the following example, a file specified in a shell variable ($filename) is retrieved from an ftp server:
filname=important.file.gz
ftp -n ftp.server.name << TheEnd
user username password
cd directory/subdir
get $filename
quit
TheEnd






Add New Comment
Viewing 2 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment