🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1804

/bin/sh redirection of stdin, stderr woes

#1804
From: Ian Watson
Date: Mon, 19 Nov 1990 12:02
46 lines
1854 bytes
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

Doing this everywhere is verbose and horrible.  Next attempt is to leave sout
and serr set to null so that the command

cmd >$sout 2>$serr

is effectively 

cmd > 2>

Now, the questions :  

(1) Are there any pitfalls with this method -- redirecting to nowhere ?

(2) Is there any way of making the intention more clear ?  I have been trying
to get sout and serr set in such a way that the effective command is

cmd >&1 2>&2

without success (syntax errors, '&' being evaluated as background
process indicator, creation of files "&1" and "&2" etc.).

Thanks in advance,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ian Watson, HP Pinewood Information Systems Division, England.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Phone :				(Intl)+44 344 763015
Unix mail (Internet) :		ian@hpopd.HP.COM
Unix mail (UUCP) :		...!hplabs!hpopd!ian
Openmail :			ian watson/pinewood,lab,hpopd
Openmail from Unix :		ian_watson/pinewood_lab_hpopd@hpopd
HPDesk :			Ian WATSON/HP1600
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Technical Details
Message-ID: <28770001@hpopd.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!hplabs!otter.hpl.hp.com!hpopd!ian

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!hplabs!otter.hpl.hp.com!hpopd!ian
From: ian@hpopd.HP.COM (Ian Watson)
Newsgroups: comp.unix.shell
Subject: /bin/sh redirection of stdin, stderr woes
Message-ID: <28770001@hpopd.HP.COM>
Date: 19 Nov 90 12:02:25 GMT
Organization: Hewlett-Packard ING-PWD, UK.
Lines: 46