Bourne shell programming question...

Dan Ts'o dan at rna.UUCP
Wed May 9 09:06:31 AEST 1984


Hi,
	I've just started to use the Bourne shell in non-trivial
command script writing and have run into a number of problems. I am
converting some shell scripts from an older shell (V6-like with variables).
	In particular,
	1) How do you read a single line from /dev/tty (or an arbitrary file,
		NOT stdin) and assign that line to a variable ?
	2) How do you arrange for a single instance of common shell code ?
		The Bourne shell has no procedures and no goto statement.

	For reading a single line into a variable from /dev/tty, I've had to
use the ridiculous:

	a=`dd if=/dev/tty count=1 2>/dev/null`

or

	a=`(read a
		echo $a) < /dev/tty`

	The read command doesn't seem to like its stdin re-directed (I know its
a builtin command). There appears to a possibility of making /dev/tty the stdin
by saying

	exec 0< /dev/tty

	but this throw away the old stdin.

	Even if these two problems have easy solution which I've overlooked,
I'd like to say that the Bourne shell sucks. If people are accurate in saying
the C-shell is worst than the Bourne shell for programming...
	I know the Korn shell has shell procedures and all its builtin commands
are supposed to be I/O redirectable.


						Cheers,
						Dan Ts'o
						...cmcl2!rna!dan



More information about the Comp.unix mailing list