home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / shell / 5348 < prev    next >
Encoding:
Text File  |  1993-01-12  |  1.6 KB  |  40 lines

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