It is currently Tue, 07 Dec 2021 02:43:32 GMT

Author Message
 Using read within a loop that parses a file line by line
This bit of code is supposed to process a list of files line by line,
and prompt you for a revision number each time.  What actually happens
is that the while read LINE ; do ; done < $FILELIST somehow interferes
with read REV command and the result is an infinite loop.  You're
never actually prompted for any input, and REV remains an empty

Can someone suggest how to fix this?

while read LINE
  cfg info $LINE | less
  echo "Revision number?"
  read REV
  rcsdiff -r${REV} $LINE | tee -a $TEMPFILE
    echo "\nWrite difference to file (y/n)?"
    read OK
    if [ $OK = y ]
      echo "Diff written to $OUTFILE"
    rm -f $TEMPFILE
done < $INFILE

 Mon, 06 Mar 2006 08:32:14 GMT   
 Using read within a loop that parses a file line by line

    You have redirected stdin, so read gets its input from the
    file. To get information from the keyboard, you need to redirect
    the input:

read REV < /dev/tty

    Chris F.A. Johnson              
    My code (if any) in this post is copyright 2003, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 Mon, 06 Mar 2006 10:08:26 GMT   
 Using read within a loop that parses a file line by line
On 17 Sep 2003 17:32:14 -0700, (David) wrote:

When you do the redirection on a command like while/do/done it affects
all the code executed within, while/do/done is regarded as one whole
block rather like { .... }

You could set up file descriptor 3 to point to the stdin before
redirecting it to the file so that inside the while/do/done block
stdin (file descriptor 0) is pointing to the file and file descriptor
3 is pointing to wherever stdin was pointing to before

read REV <&3

read OK <&3

This line can crash on unexpected user input to stop that
irregardless of what they type the variable should be quote

if [ "$OK" = y ]

done 3<&1 <$FILENAME


echo alru_aafrieh...@ittnreen.tocm |sed 's/\(.\)\(.\)/\2\1/g'

 Tue, 07 Mar 2006 08:29:18 GMT   
 Using read within a loop that parses a file line by line
On 18 Sep 2003 02:08:26 GMT, "Chris F.A. Johnson" <> wrote:

Not all systems support /dev/tty. Also stdin in the program doesn't
have to point to the process terminal (eg; if not redirected from a file
then this fails if run from a socket)


echo alru_aafrieh...@ittnreen.tocm |sed 's/\(.\)\(.\)/\2\1/g'

 Tue, 07 Mar 2006 08:29:41 GMT   
 Using read within a loop that parses a file line by line

That's true, but unless it's run as a daemon somehow, it probably does
have a controlling terminal, and /dev/tty is the best bet for getting
at that, whether stdin has been redirected or not.


 Tue, 07 Mar 2006 11:08:32 GMT   
   [ 5 post ] 

Similar Threads

1. read from stdin while reading line by line a file

2. Parsing a line read in from a file

3. Shell Scripts read and parse lines from a file

4. Reading from a file and parsing the lines

5. Using awk or the shell to parse a file containing multiple line groups of data

6. parsing a line from file using shell scripts

7. line by line reading of the lines in list

8. Reading a script file line by line.

9. reading files line-be-line?

10. read a file line by line in csh script

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software