From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16980 invoked by alias); 4 Apr 2016 11:03:59 -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: 38236 Received: (qmail 17240 invoked from network); 4 Apr 2016 11:03:57 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.1 X-AuditID: cbfec7f5-f792a6d000001302-dc-570247bb766d Date: Mon, 04 Apr 2016 11:53:44 +0100 From: Peter Stephenson To: Cuong Manh Le , Zsh hackers list Subject: Re: Redirection order with multios option set Message-id: <20160404115344.72845d97@pwslap01u.europe.root.pri> In-reply-to: References: 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+NgFrrJLMWRmVeSWpSXmKPExsVy+t/xa7q73ZnCDVomKlhM2rGE2eJg80Mm ByaPnbPusnusOviBKYApissmJTUnsyy1SN8ugSvjxJPrbAVTeCsWXF3K0sB4jquLkZNDQsBE YkvLbyYIW0ziwr31bCC2kMBSRomrLZZdjFxAdgOTxPxdG9kgnNOMEm+PtjJBOGcYJZ6d3sEM 0sIioCqxubOPBcRmEzCUmLppNmMXIweHiEC4xIfp2SBhYQEzic8zprKD2LwC9hLfl21hBLE5 BYIlzm/dBrU5QGL5sUZWEJtfQF/i6t9PUNfZS8y8coYRoldQ4sfke2CrmAW0JDZva2KFsOUl Nq95ywwxR13ixt3d7BMYhWchaZmFpGUWkpYFjMyrGEVTS5MLipPSc430ihNzi0vz0vWS83M3 MUIC/OsOxqXHrA4xCnAwKvHwfjjKGC7EmlhWXJl7iFGCg1lJhLfRjSlciDclsbIqtSg/vqg0 J7X4EKM0B4uSOO/MXe9DhATSE0tSs1NTC1KLYLJMHJxSDYysb/Jboh+oH1PgXFzYfq8lsbub zzkzeX7rnJcTrU66Fi234jH+vFf5ImvJVCP/zNbjG6+v/5LXwW0kZZPr+y4ied/RGnaDYKE3 EyeYJ79OML2WzZhxJmjtnpileS3PrU68FNgnmHxA1Ghe1O3WRbHn507mP+4WE+rFxTirq3mj jd0ys4gzpUosxRmJhlrMRcWJAGb2rE9sAgAA On Mon, 04 Apr 2016 17:27:30 +0700 Cuong Manh Le wrote: > $ echo a >/tmp/test >&1 > > write two lines `a` to file `/tmp/test`. > > From user perspective, this behavior seems to be in-consistent to me. It's expected --- redirections are evaluated in order. There is no memory of what stdout used to be before we started evaluating redirections, which is what you'd need to get this to do what you thought. However, it could do with being documented. See if this explains it. pws diff --git a/Doc/Zsh/redirect.yo b/Doc/Zsh/redirect.yo index 35fa773..66160a6 100644 --- a/Doc/Zsh/redirect.yo +++ b/Doc/Zsh/redirect.yo @@ -234,6 +234,25 @@ example(date >foo | cat) writes the date to the file `tt(foo)', and also pipes it to cat. +Note also that redirections are always expanded in order. This happens +regardless of the setting of the tt(MULTIOS) option, but with the option +in effect there are additional consequences. For example, +the meaning of the expression tt(>&1) will change after a previous +redirection: + +example(date >&1 >output) + +In the case above, the tt(>&1) refers to the standard output at the +start of the line; the result is similar to the tt(tee) command. +However, consider: + +exmaple(date >output >&1) + +As redirections are evaluated in order, when the tt(>&1) is encountered +the standard output is set to the file tt(output) and another copy of +the output is therefore sent to that file. This is unlikely to be what +is intended. + If the tt(MULTIOS) option is set, the word after a redirection operator is also subjected to filename generation (globbing). Thus