HELP: how to reset redirected standard input in "sh" programs ?

Maarten Litmaath maart at cs.vu.nl
Sat Jun 16 07:05:32 AEST 1990


In article <1990Jun13.210212.16003 at portia.Stanford.EDU>,
	jerzy at 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 at cs.vu.nl, uunet!cs.vu.nl!maart



More information about the Comp.unix.questions mailing list