When you use a
Here Document, the shell effectively does
echo -e "1\n2\n" > /tmp/tempname
./test < /tmp/tempname
which means that if the program has exhausted all input before it finishes reading from stdin, then any further input is handled the same way as any other end-of-file input situation. If you need to read additional input in the shell you will need to do that before you invoke the program in the shell script.
You can either pass the additional data in as an argument to the shell script:
./test << EOF
1
2
$1
EOF
Here,
$1
is the first argument to the shell script, and you would use it as
./test.sh 7
Or you can read the data in the shell script, and pass it on to your program in a similar manner
echo -n "Enter a number: "
read arg
./test << EOF
1
2
$arg
EOF
For more information on
Here Documents, see here:
https://tldp.org/LDP/abs/html/here-docs.html[
^]