Hector Chu wrote:
input-line.sh is:

bash ./input-line.sub
this line for input-line.sub

with input-line.sub being:

read line
echo line read by $0 was \`$line\'

The test is run by executing: bash < input-line.sh.

How does input-line.sub manage to read from the correct point in the
input file? Doesn't the parent bash read the whole lot into its
buffer, so that the child bash starts reading from the end of the
file?

No.  That's the point of the test.  Posix requires that shells rewind
or otherwise manipulate the read pointer in a script read from the
standard input to preserve this kind of synchronization between parent
and child processes.

One way to accomplish this is to read the script one character at a
time.  Bash uses a set of buffered input functions (found in input.c)
to handle its own buffering and input stream rewinding.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    [EMAIL PROTECTED]    http://cnswww.cns.cwru.edu/~chet/


Reply via email to