Piping stderr in Korn and/or Bourne

Brad Appleton brad at SSD.CSD.HARRIS.COM
Mon Apr 9 02:58:37 AEST 1990


Thank you to all who replied to my Korn-shell question on piping 
stderr but leaving stdout alone! Below is a summary of my e-mail
replies (you all saw the ones that were posted):

Contents of file "tst":

	#!/bin/ksh
	print "this is stdout"
	print -u2 "this is stderr"

Solutions:

Michael T. Sullivan, Alan M. Carrol, and Andy Behrens all suggested:

	$ tst 2>&1 >/dev/tty | sed 's/std/STD/'

This actually didnt work for me (probably to a slight system diff)
I got "ksh: cannot create device". A minor variation fixed this up:

	$ tst 2>&1 >`tty` | sed 's/std/STD/'
	this is stdout
	this is STDerr

Alan M. Carrol also suggested:

	$ tst 3>&2 2>&1 >&3 | sed 's/std/STD/'
	this is stdout
	this is STDerr

(The old swap method) Works like a charm, also has the added benefit
that it truly does leave stdout in the same place it was (tty or not).
I hereby declare it the winner (IMHO of course ;-)

Thank you all once again!
-=-=-=-=-=-=-=-=-=-=-= "And miles to go before I sleep." =-=-=-=-=-=-=-=-=-=-=-
 Brad Appleton         Harris Computer Systems         brad at ssd.csd.harris.com
 (305) 973-5007        Fort Lauderdale, FL USA        {uunet,novavax}!hcx1!brad
-=-=-=-=-=-=-=-=-=-= Disclaimer: I said it, not my company! -=-=-=-=-=-=-=-=-=-



More information about the Comp.unix.questions mailing list