zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-workers@zsh.org
Cc: Pierre Neidhardt <ambrevar@gmail.com>
Subject: Re: Redirection bug for stderr?
Date: Thu, 20 Nov 2014 16:08:16 +0000	[thread overview]
Message-ID: <20141120160816.0d259011@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <20141120104440.GA23262@gmail.com>

On Thu, 20 Nov 2014 11:44:40 +0100
Pierre Neidhardt <ambrevar@gmail.com> wrote:
> I recently noticed a somewhat unexpected behaviour with a configuration-less zsh 5.0.7:
> 
> 	 $ ls /root >/dev/null 2>&1
>    $ ls /root 2>/dev/null | cat
>    $ ls /root >/dev/null 2>&1 | cat
> 	 ls: cannot open directory /root: Permission denied
> 
> I believe last error line should not appear.

I suspect you're hitting this.

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'.


  reply	other threads:[~2014-11-20 16:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-20 10:44 Pierre Neidhardt
2014-11-20 16:08 ` Peter Stephenson [this message]
2014-11-20 16:58   ` Stephane Chazelas
2014-11-20 20:28     ` Pierre Neidhardt
2014-11-21 11:29     ` [PATCH][DOC] " Stephane Chazelas

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=20141120160816.0d259011@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=ambrevar@gmail.com \
    --cc=zsh-workers@zsh.org \
    /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).