🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1807

Re: /bin/sh redirection of stdin, stderr woes

#1807
From: Maarten Litmaath
Date: Tue, 20 Nov 1990 22:58
37 lines
1493 bytes
In article <28770001@hpopd.HP.COM>,
	ian@hpopd.HP.COM (Ian Watson) writes:
)I want to have a Bourne shell script that does something like :
)
)cmd >$sout 2>$serr
)
)Under certain conditions, sout and serr may be set earlier in the script to
)given files, otherwise the stdin and stderr from the calling process are to
)be inherited.  The simple way of doing this is to have something like :
)
)if vars_were_set_in_script ; then
)	cmd >$sout 2>$serr
)else
)	cmd
)fi

Try this:

	(
		test $vars_are_set && exec > $sout 2> $serr
		cmd
	)

Alternatively:

	if some_condition
	then
		OUT="> $outputfile"
		ERR="2> $errorfile"
	fi
	...
	eval "cmd $OUT $ERR"
--
"Please DON'T BREAK THE CHAIN!  Terry Wood broke the chain and ended up
writing COBOL PROGRAMS.  Three days later, he found his Blue Star Tatoo
Letter, made 20 copies and mailed them out.  He found a good job writing
compilers."  --  tjw@unix.cis.pitt.edu (Terry J. Wood)
Technical Details
Message-ID: <8306@star.cs.vu.nl>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!mit-eddie!bloom-beacon!eru!hagbard!sunic!mcsun!hp4nl!star.cs.vu.nl!maart
References: <28770001@hpopd.HP.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!wuarchive!mit-eddie!bloom-beacon!eru!hagbard!sunic!mcsun!hp4nl!star.cs.vu.nl!maart
From: maart@cs.vu.nl (Maarten Litmaath)
Newsgroups: comp.unix.shell
Subject: Re: /bin/sh redirection of stdin, stderr woes
Message-ID: <8306@star.cs.vu.nl>
Date: 20 Nov 90 22:58:08 GMT
References: <28770001@hpopd.HP.COM>
Sender: news@cs.vu.nl
Reply-To: maart@cs.vu.nl (Maarten Litmaath)
Organization: VU Dept. of Computer Science, Amsterdam, The Netherlands
Lines: 37