Stupid shell I/O redirection question...

dan at rna.UUCP dan at rna.UUCP
Mon Feb 23 15:12:01 AEST 1987


	Forgive me for being lazy and not finding the (one true) answer myself,
but I've always wanted to know how to do the following:

	I have a shell script which issues commands that generate output on
both the stdout and stderr (1 and 2). I want to redirect both stdout and stderr
of the script through a pipe (without hacking the script (the same question
would apply to a single program that wrote on 1 and 2, anyways). Like this:

cmd:
	time date
	time who

	The time command writes its answer to stderr while date and who write
to stdout. I then wish to redirect both outputs to a pipe, say tee to both see
and capture the results (I know I could use script, etc.) The best solution I
could find is:

	(cmd 2>&1) | tee log

	I believe this wastes a shell, but just removing the () doesn't work
since the 2>&1 (dup syscall) happens before the pipe is created. Perhaps

	(exec cmd 2>&1) | tee log

	Well is there some other syntax or funny combination of >|12& to use ?



More information about the Comp.unix.questions mailing list