(this is indirectly a part of a much larger homework assignment)
I have something like
while read LINE
do
stuff-done-to-$LINE
echo "Enter input:"
read INPUT
stuff-done-to-$INPUT
done < infile
I can’t find a successful way of using the console/default stdin for the second read, instead of the redirected stdin.
Needs to be pure bourne script.
I believe this is supported in the Bourne shell:
Input is alternated between the file and the user. In fact, this would be a neat way to issue a series of prompts from a file.
This redirects the file “infile” to the file descriptor number 3 from which the first
readgets its input. File descriptor 0 isstdin, 1 isstdoutand 2 isstderr. You can use other FDs along with them.I’ve tested this on Bash and Dash (on my system sh is symlinked to dash).
Of course it works. Here’s some more fun:
This alternates printing the contents of two files, discarding the extra lines of whichever file is longer.
Doc1 only has two lines. The third line and subsequent lines of doc2 are discarded.