From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19885 invoked by alias); 20 Nov 2014 16:18:28 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33722 Received: (qmail 13749 invoked from network); 20 Nov 2014 16:18:26 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7f956d000005ed7-bf-546e11f22d87 Date: Thu, 20 Nov 2014 16:08:16 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Cc: Pierre Neidhardt Subject: Re: Redirection bug for stderr? Message-id: <20141120160816.0d259011@pwslap01u.europe.root.pri> In-reply-to: <20141120104440.GA23262@gmail.com> References: <20141120104440.GA23262@gmail.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrILMWRmVeSWpSXmKPExsVy+t/xy7qfBPNCDFpfMFvs+3WN1eJg80Mm ByaPnbPusnusOviBKYApissmJTUnsyy1SN8ugSvjw5PdjAV3eCvONq1lbGBcydXFyMkhIWAi cenCd0YIW0ziwr31bF2MXBxCAksZJabc/MoI4fQzSfRMm8LcxcjBwSKgKrH8pBZIA5uAocTU TbPBmkUExCXOrj3PAmIzC2hKnL90hA3EFhbQkNj56zNYDa+AvcSJ1UvYQWxOAX2JAy2dYCOF BPQkZt/RAQnzA4Wv/v3EBHGPvcTMK2egWgUlfky+BzVeS2LztiZWCFteYvOat8wTGAVnISmb haRsFpKyBYzMqxhFU0uTC4qT0nON9IoTc4tL89L1kvNzNzFCgvXrDsalx6wOMQpwMCrx8F6Y lRsixJpYVlyZe4hRgoNZSYRXjj0vRIg3JbGyKrUoP76oNCe1+BAjEwenVANjzKV9T1736uq2 f0/YtJcz44bRJymZv5e0BaWTP294mXrw4otQR2m937v/9ys33nm0mfus5aKIyiU6ln5vc0Q3 dbZ0+05706PtH3x4Uc7jrCbe4LX6qe+D9solm2R7LuldsMhe4/+E5NU3rG73LG0TqLnbkNCo w9QXIerFVrv+XsFstT6urxlKLMUZiYZazEXFiQCKG+vBNAIAAA== On Thu, 20 Nov 2014 11:44:40 +0100 Pierre Neidhardt 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'.