Stupid shell I/O redirection question...

dce at mips.UUCP dce at mips.UUCP
Wed Feb 25 14:47:23 AEST 1987


File descriptors can be handled very clearly and simply by using
the fact that 'exec' with no command can be used to redirect
file descriptors in the current shell.

Let's say that you want to redirect standard error to a file and
standard out to the old standard error. This can be done by

	exec 9>&1		# fd 9 is now a duplicate of stdout
	exec 1>&2		# stdout is now a duplicate of stderr
	2>file command...	# stderr goes to 'file'
	exec 1>&9		# stdout restored to original

The idea is that you can save any file descriptor in one that isn't
being used (9 is a good candidate since it stands out), and restore
it at a later time.

The Bourne shell has some very useful features hidden in it (I still
am amazed at the prompt changing on the fly that is implemented using
traps and an infinite loop sending signals).
-- 
			David Elliott

UUCP: 	{decvax,ucbvax,ihnp4}!decwrl!mips!dce, DDD:  	408-720-1700



More information about the Comp.unix.questions mailing list