jerzy@portia.Stanford.EDU (Jerzy Czaplicki) (06/14/90)
Hi, I am writing a program that's supposed to be executed by "sh" and have a problem with data reading. The program creates a text file that is sequentially read to the end. Then a new, updated text file is created, its contents should be read & compared to the old one. The problem here is that "read" works with the first file only. The standard input is not reset to the beginning of the file and program tries to read the second file from the line number where the first one ended. Does anyone know how to make it read file from the beginning ? {I work on a system identifying itself as "Ultrix-32 V3.1 (Rev. 9).} Another problem: Command "sh prgm < data" works fine and data file is read as supposed. But input redirection within prgm doesn't work at all (keyboard is assumed to be standard input in spite of all "<" characters and contrarily to what the manual says). Why ? Thanks in advance, Jerzy. ------- Newsgroups: comp.unix.ultrix Subject: Re: biz.dec.* in the UK Summary: Expires: References: <1990Jun12.172822.20583@computing-maths.cardiff.ac.uk> Sender: Followup-To: Distribution: Organization: AIR, Stanford Universit Keywords: -- Jerzy <jerzy@portia.stanford.edu> <j.jc@macbeth.stanford.edu>
maart@cs.vu.nl (Maarten Litmaath) (06/16/90)
In article <1990Jun13.210212.16003@portia.Stanford.EDU>, jerzy@portia.Stanford.EDU (Jerzy Czaplicki) writes: )I am writing a program that's supposed to be executed by "sh" and )have a problem with data reading. The program creates a text file )that is sequentially read to the end. Then a new, updated text file )is created, its contents should be read & compared to the old one. ) )The problem here is that "read" works with the first file only. )The standard input is not reset to the beginning of the file and )program tries to read the second file from the line number where )the first one ended. ) )Does anyone know how to make it read file from the beginning ? ){I work on a system identifying itself as "Ultrix-32 V3.1 (Rev. 9).} This command will (re)connect stdin to (the beginning of) `file': exec < file You can specify an alternative file descriptor too: exec 3< file ...to be used as follows: read foo <&3 If your sh version doesn't allow input redirection with a `read' command, you can use the following alternative: exec 9<&0 <&3 # remember fd 0 (stdin) in fd 9, i.e. # make fd 9 a duplicate of 0 (see dup(2)); # then connect stdin to fd 3 read foo exec <&9 # reconnect stdin to the original stream )Another problem: Command "sh prgm < data" works fine and data file )is read as supposed. But input redirection within prgm doesn't )work at all (keyboard is assumed to be standard input in spite of )all "<" characters and contrarily to what the manual says). Why ? ERROR 0A4F7: TOO FEW CLUES GIVEN. ABEND -- "COBOL is the revenge of some witch burned |Maarten Litmaath @ VU Amsterdam: in Salem, [...]" (Bill Davidsen) |maart@cs.vu.nl, uunet!cs.vu.nl!maart