read not reading

read not reading

Post by Kyle Tuck » Wed, 13 Jan 1993 06:08:39



Perhaps I'm losing it, but I swear this is what I see happening.

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.

Any help/experience with this greatly appreciated!

- Kyle
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Kyle Tucker - Email Administrator  |            Progress Software Corporation

(617)280-4565                      |            Bedford, Mass. 01730
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

 
 
 

read not reading

Post by Eric Gis » Thu, 14 Jan 1993 04:07:18


   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.

 
 
 

1. Problem with read not reading fixed

FYI,
A few weeks ago, I posted about this script not continuing the read
statements even though I new there were more lines in the file

cat file | while read LINE
do
        some stuff
done

Many of you replied suggesting I exec with file descriptor redirect from
$0. This did not work. What was found was that I was doing remote shells (rsh)
inside the do loop and there is some problem with stdin getting munged if the
-n arg is not used. The entire script worked fine as soon as the -n's were
put in without the exec read < $0 statements. The SunOS man page for rsh
explains the -n option's purpose.

- Kyle
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Kyle Tucker - Email Administrator  |            Progress Software Corporation

(617)280-4565                      |            Bedford, Mass. 01730
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

2. Boot program for Linux and DOS

3. LILO answers HERE read read read

4. Solaris Java/C++ development environment recomendations

5. Solaris '/usr/bin/read' not reading?

6. rsh -l problem (revisit)

7. read() does not return bytes read from FIFO - pipe.txt [1/1]

8. Problem with printing 8 bits characters (Norwegian)

9. Not a good read (Was RE:A good read)

10. read in bash does not read a line without trailing \n

11. bash read does not read

12. Reading a directory and knowing which type of file am I reading

13. Read & Read/Write Groups