home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!cs.utexas.edu!torn!watserv2.uwaterloo.ca!watserv1!mks.com!giga!eric
- From: eric@giga.mks.com (Eric Gisin)
- Subject: Re: read not reading
- In-Reply-To: tucker@bedford.progress.COM's message of Mon, 11 Jan 1993 21:08:39 GMT
- Message-ID: <ERIC.93Jan12140718@giga.mks.com>
- Sender: eric@mks.com (Eric Gisin)
- Organization: Mortice Kern Systems Inc., Waterloo, Ontario, CANADA
- References: <1993Jan11.210839.9498@progress.com>
- Date: Tue, 12 Jan 1993 19:07:18 GMT
- Lines: 27
-
- In article <1993Jan11.210839.9498@progress.com> tucker@bedford.progress.COM (Kyle Tucker) writes:
-
- cat file | while read LINE
- do
- if [ certain things are true about $LINE ]
- then
- do some stuff based on values in $LINE
- fi
- done
-
- Now, if I do "some stuff" , which is a lot of text hacking, etc, but
- absolutely no exits,breaks,continues,etc, the read command sees no
- more lines in the file. If I don't do "some stuff", then it reads next
- line fine. sh -x shows the read is actually occuring, but ending as
- if it sees EOF. Has this been seen before? This also occurs if the reads
- are done through standard input.
-
- ---
-
- Most likely one of the commands in "some stuff" reads stdin.
- The only safe commands to read stdin in a shell script like this
- are the "read" built-in and "line", which should do unbuffered input.
- Commands like "head -3" and "sed 3q" may read a complete buffer from the pipe
- (probably the rest of "file") and the next "read" will get EOF.
-
- Least likely is the shell does fflush(NULL) before forking on a POSIX.1 system.
- This will discard the stdin buffer in shells that use stdio.
-