Advanced shell scripting question :-)

Steven W. Orr steveo at syslang.net
Thu Sep 5 09:31:58 EDT 2002


On Wed, 4 Sep 2002, Marc Evans wrote:

=>How about something like this:
=>
=>	p 3>ERR 2>&3 2>&1 | tee OUTERR

Interesting, but it doesn't quite work. This translates into english as:
"Run p and redirect channel 3 to the ERR file. Then dup channel 2 onto 
channel 3, and then dup channel 2 to channel 1. Next take the whole 
shebang and pipe it out to tee where it all goes to both."

This doesn't actually work, and to be honest I didn't quite see why not,
but another person suggested that the solution might somehow use process
substitution. So I tinkered a bit and the final solution is:

[drum roll please!]


p 3> >(tee ERR) 2>&1 2>&3 | tee BOTH


Many thanks to all who responded. :-)


=>On Wed, 4 Sep 2002, Steven W. Orr wrote:
=>
=>> I have a program (which we shall call p) which produces text to both
=>> stdout and stderr.
=>>
=>> I want the following three things to happen when I run p:
=>>
=>> 1. I want both stdout and stderr to go to the screen
=>>
=>> 2. I want stdout and stderr combined in a file
=>>
=>> 3. I want an error log file to only contain stderr.
=>>
=>> p 2>&1 | tee outnerr # Solves 1 and 2
=>>
=>> p 2> errlog	# Solves 3 but breaks 1 and 2
=>>
=>> p 2> errlog | tee out # Solves 3 but also breaks 1 and 2.
=>>
=>> Any takers?


-- 
-Time flies like the wind. Fruit flies like a banana. Stranger things have -
-happened but none stranger than this. Does your driver's license say Organ
-Donor?Black holes are where God divided by zero. Listen to me! We are all-
-individuals! What if this weren't a hypothetical question? steveo at syslang.net




More information about the gnhlug-discuss mailing list