/bin/sh redirection of stdin, stderr woes
Maarten Litmaath
maart at cs.vu.nl
Wed Nov 21 09:58:08 AEST 1990
In article <28770001 at hpopd.HP.COM>,
ian at 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 at unix.cis.pitt.edu (Terry J. Wood)
More information about the Comp.unix.shell
mailing list