zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@brasslantern.com>
To: Zsh hackers list <zsh-workers@sunsite.dk>
Subject: Multios again (Re: Piping stderr (was Re: Two bug reports))
Date: Sat, 23 Mar 2002 23:47:18 +0000	[thread overview]
Message-ID: <1020323234719.ZM29486@candle.brasslantern.com> (raw)
In-Reply-To: <1020323224514.ZM29171@candle.brasslantern.com>

On Mar 23, 10:45pm, Bart Schaefer wrote:
}
} The same problem with MULTIOS occurs with `3>&2 2>&1 1>&3 |'.

Given that we have the >(...) syntax, I'm wondering there should be a way
to allow multios for redirections but not for pipes.  That would mean that
in `command >file1 >file2 | prog', file1 and file2 would get output but the
pipe would get nothing.  That way, `command 2>&1 >file | prog' would work
the way it does in other shells, and if you really mean for `prog' to get
a copy of the input you can write `command 2>&1 >file >>(prog)' instead.

It further would mean that `command 2>>(prog1) >file | prog2' would send
ONLY the output of `prog1' through `prog2', which seems to be partly what
Wayne was getting at with his question.

Various weird tidbits while I'm on the subject:

Using `1>&1' creates some pretty strange effects; it duplicates stdout
2**N times (where N is the number of uses of `1>&1').  Let's look at a few
examples; the first two just set up the context.

zsh% (print -u2 foo; print bar) >>(tr a-z A-Z)
foo
zsh% BAR

We know that the >(...) runs asynchronously, so that's fine.

zsh% (print -u2 foo; print bar) >>(tr a-z A-Z) | wc
foo
      2       2       8

Shows that the stdout of the >(...) expression also goes to the pipe.  That
implies a simple way to make >(...) act semi-synchronously: pipe the whole
command to `cat'.

Now for the strange stuff:

zsh% (print -u2 foo; print bar) 1>&1 >>(tr a-z A-Z) | cat
foo
bar
bar
BAR

So `cat' got two copies of the original stdout and >(...) got one.  Yet:

zsh% (print -u2 foo; print bar) >>(tr a-z A-Z) 1>&1 | cat
foo
bar
bar
BAR
BAR

Here, 1>&1 duplicated the input to >(...) as well as to the pipe.  At first
I thought it had somehow duplicated the output of >(...), but:

zsh% (print -u2 foo; print bar) 2>>(tr a-z A-Z) 1>&1 | cat
bar
bar
FOO

Now for the real silliness:

zsh% (print -u2 foo; print bar) 1>&1 >>(tr a-z A-Z) 1>&1 | cat
foo
bar
bar
bar
bar
BAR
BAR

Can this really be the way it's supposed to work?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


  reply	other threads:[~2002-03-23 23:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-22 12:24 Two bug reports: alias/function disagreements; incorrect redirection David Hughes
2002-03-22 12:41 ` Peter Stephenson
2002-03-23 21:18   ` Piping stderr (was Re: Two bug reports) Wayne Davison
2002-03-23 22:45     ` Bart Schaefer
2002-03-23 23:47       ` Bart Schaefer [this message]
2002-03-24  9:01       ` Wayne Davison
2002-03-24 16:47         ` Borsenkow Andrej
2002-03-24 19:02           ` Bart Schaefer
2002-03-24 19:09             ` Bart Schaefer
2002-03-24 19:50             ` PATCH: (Doc) " Bart Schaefer
2002-03-25  0:17             ` Wayne Davison

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=1020323234719.ZM29486@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /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).