Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: stdout bug? (redirection not honored)



"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



Messages sorted by: Reverse Date, Date, Thread, Author