Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!think.com!mintaka!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!mucs!logitek!grep!frank From: frank@grep.co.uk (Frank Wales) Newsgroups: comp.unix.shell Subject: Re: /bin/sh redirection of stdin, stderr woes Message-ID: <1990Nov23.131308.21336@grep.co.uk> Date: 23 Nov 90 13:13:08 GMT References: <28770001@hpopd.HP.COM> Reply-To: frank@grep.co.uk (Frank Wales) Organization: Grep Limited, LEEDS, UK Lines: 23 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 Here is a short script which demonstrates a technique you could try: #!/bin/sh - cmd=cat # example command # sample target set-up case $# in 0) stdout="&1"; stderr="&2";; # default both 1) stdout="$1"; stderr="&2";; # specify stdout, default stderr 2) stdout="$1"; stderr="$2";; # specify both *) echo usage: $0 [stdout [stderr]] >&2; exit 1;; esac # command evaluation evalarg="$cmd >$stdout 2>$stderr" # build the command line eval $evalarg # do it -- Frank Wales, Grep Limited, [frank@grep.co.uk<->uunet!grep!frank] Kirkfields Business Centre, Kirk Lane, LEEDS, UK, LS19 7LX. (+44) 532 500303