From: Peter Stephenson <pws@csr.com>
To: zsh-workers@sunsite.dk
Subject: Re: stdout bug? (redirection not honored)
Date: Wed, 01 Nov 2006 18:46:07 +0000 [thread overview]
Message-ID: <200611011846.kA1Ik7tN022102@news01.csr.com> (raw)
In-Reply-To: <20061101184128.GA95245@arctic.icelab.net>
"J.D. Laub" wrote:
> Is this a bug?
No, see below.
> % uname -s -r -v -m -p -i -o
> Linux 2.4.21-32.0.1.ELsmp #1 SMP Tue May 17 17:52:23 EDT 2005 i686 i686 i386
> GNU/Linux
> % echo $ZSH_VERSION > /dev/null | cat # should print nothing, but...
> 4.3.2
>
> The problem becomes an issue when you have a command that generates
> something on both stdout and stderr, and you want to dump the stdout
> and page through the stderr:
>
> % foo 2>&1 > /dev/null | more
>
> I'm hoping someone says this can be addressed by setting an
> option. :-)
Yes, indeed.
3.26: Why is my output duplicated with `foo 2>&1 >foo.out | bar'?
This is a slightly unexpected effect of the option MULTIOS, which is
set by default. Let's look more closely:
foo 2>&1 >foo.out | bar
What you're probably expecting is that the command `foo' sends its
standard output to the pipe and so to the input of the command `bar',
while it sends its standard error to the file `foo.out'. What you
actually see is that the output is going both to the pipe and into the
file. To be more explicit, here's the same example with real commands:
% { print output; print error >&2 } 2>&1 >foo.out | sed 's/error/erratic'
erratic
output
% cat foo.out
output
and you can see `output' appears twice.
It becomes clearer what's going on if we write:
% print output >foo1.out >foo2.out
% cat foo1.out
output
% cat foo2.out
output
You might recognise this as a standard feature of zsh, called `multios'
and controlled by the option of the same name, whereby output is copied
to both files when the redirector appears twice. What's going on in the
first example is exactly the same, however the second redirector is
disguised as a pipe. So if you want to turn this effect off, you need
to unset the option `MULTIOS'.
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
next prev parent reply other threads:[~2006-11-01 18:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-01 18:41 J.D. Laub
2006-11-01 18:46 ` Peter Stephenson [this message]
2006-11-01 22:15 ` J.D. Laub
2006-11-02 1:34 ` Wayne Davison
2006-11-01 18:59 ` Danek Duvall
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=200611011846.kA1Ik7tN022102@news01.csr.com \
--to=pws@csr.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).