zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ifh.de>
To: zsh-users@math.gatech.edu (Zsh users list)
Subject: Re: Redirect &2 into a command - HowTo
Date: Fri, 24 Oct 1997 17:00:00 +0200	[thread overview]
Message-ID: <199710241500.RAA11438@hydra.ifh.de> (raw)
In-Reply-To: "Helmut Jarausch"'s message of "Fri, 24 Oct 1997 16:36:52 MST." <jarausch-971024163649.A14799@numa1>

Helmut Jarausch wrote:
> Sorry if this is a FAQ (I didn't find it there).

You may find it in the general shell FAQs; it'll work in any proper
shell (i.e. not csh, tcsh).

> Is there any possibility to redirect STDERR to a command like 'xless'
> without redirecting  STDOUT as well?

The trick is to use a spare FD to swap the first two.

mycmd 3>&1 1>&2 2>&3 3>&- | xless

which means 1) open a new fd 3 to stdout (the pipe) 2) redirect stdout
to where stderr is 3) now move stderr to 3, which is the original
stdout 4) to be tidy, close the spare fd, though in this case that's
not actually necessary (I won't bore you).

One important extra which isn't in anyone else's FAQ:  in zsh, you need
to `setopt nomultios', since a `multio' will interpret the `1>&2' as
saying you want stdout to go to both the old stderr *and* the pipe,
which in this case you don't.  (Do we need an option `pipemultios', which
is off by default?)

-- 
Peter Stephenson <pws@ifh.de>       Tel: +49 33762 77366
WWW:  http://www.ifh.de/~pws/       Fax: +49 33762 77413
Deutsches Elektronen-Synchrotron --- Institut fuer Hochenergiephysik Zeuthen
DESY-IfH, Platanenallee 6, 15738 Zeuthen, Germany.


      parent reply	other threads:[~1997-10-24 15:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-24 14:36 Helmut Jarausch
1997-10-24 14:57 ` Andrew Main
1997-10-24 15:00 ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199710241500.RAA11438@hydra.ifh.de \
    --to=pws@ifh.de \
    --cc=zsh-users@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).