|
From: | Chet Ramey |
Subject: | Re: How does the input-line test work? |
Date: | Fri, 29 Aug 2008 16:21:49 -0400 |
User-agent: | Thunderbird 2.0.0.16 (Macintosh/20080707) |
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 chet@case.edu http://cnswww.cns.cwru.edu/~chet/
[Prev in Thread] | Current Thread | [Next in Thread] |