Skip to content

Month: March 2014

heredoc to feed an interactive program

Let this interactive.sh be the interactive program:
[bash]#!/bin/sh
read input1
read input2
echo $input1 $input2
[/bash]

This is a script feed.sh (in the same directoty) that uses heredoc to feed two lines to interactive.sh:
[bash]#!/bin/sh
./interactive.sh << EOF
asdf
zxcv
EOF
[/bash]

It work as:
[bash]$ ./feed.sh
asdf zxcv
[/bash]