From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,b27a6df16e1589f0 X-Google-Attributes: gidfee84,public From: Timo Felbinger Subject: Re: no /dev/stderr ? Date: 2000/02/25 Message-ID: #1/1 X-Deja-AN: 589802388 References: <38B48886.6AB7691C@thynne.psych.nwux.edu> <240220000949047167%harris@zk3.dec.com> Content-Type: TEXT/PLAIN; charset=US-ASCII X-Complaints-To: usenet@zeppelin.rz.uni-potsdam.de X-Trace: zeppelin.rz.uni-potsdam.de 951472070 17919 141.89.72.92 (25 Feb 2000 09:47:50 GMT) Organization: University of Potsdam Mime-Version: 1.0 Reply-To: Timo.Felbinger@quantum.physik.uni-potsdam.de NNTP-Posting-Date: 25 Feb 2000 09:47:50 GMT Newsgroups: comp.unix.osf.osf1 On Thu, 24 Feb 2000, Bob Harris wrote: > [[ This message was both posted and mailed: see > the "To," "Cc," and "Newsgroups" headers for details. ]] > > In article <38B48886.6AB7691C@thynne.psych.nwux.edu>, Usman Muzaffar > wrote: > >Tru64 4.0 - I can't see a /dev/stderr in the device > >hierarchy. On other unices (linux, solaris) it's usually > >a symlink to the device that corresponds to fd 2. > >Can I create it myself? > > > >Isn't this POSIXish? Say I have a Bourne shell script > >whose output I want to direct to stderr or a file or > >/dev/null, depending on a switch. How can I do it if > >there's no way to reference /dev/stderr ? > > In the Bourne or Korn shells if you want to redirect I/O to stderr, you > do the following: > > command args 1>&2 > This was my first idea, too, but it won't help if you want to do something like command args 2> $logfile where $logfile is either /dev/null or stderr: > and >& are different redirection operators, and unfortunately, they can't be the result of a variable expansion. /dev/stderr is there for a reason. Some (clumsy) workarounds: - use lsof -p -a -d 2 to determine what descriptor 2 is actually connected to, - or use a pipeline like { command1 command2 . . . } 2>&1 | { case $logfile in stderr ) cat >& 2 ;; * ) cat > $logfile ;; esac } Regards, Timo Felbinger