From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29861 invoked by alias); 15 Sep 2011 13:03:59 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 16365 Received: (qmail 10111 invoked from network); 15 Sep 2011 13:03:54 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at yahoo.fr does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.fr; s=s1024; t=1316091504; bh=395kwLzXdoignqvPQj8mPpjh6p2tnhpBWVdIZ7sLABg=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:Date:From:To:Cc:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To:User-Agent; b=D97U9YowgDUaaZtfal19cpyHrtVl2QwX4UD2q5EwpNEf4KOhA3dWO5O5KMELdGjetL9bJQQDJsaUDCoXh0AJ6q+XnlyRKgwDjHb7g/73kjbRAtZ7dFjWAVv9fjr5ze+q1zkObJ26iR/uncb3d3UPcDYCRREYyTy5T8W2uufOqzw= X-Yahoo-Newman-Id: 821486.74467.bm@smtp129.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: cQ7Wy4YVM1nBrolA6NwMLNrQ6MsUV07F1n5DgHL9YeA2UjH JZj9L2SVo_1QxW.h2RC7EsQfTVKVeWnHAYzW5lLtPSjxR8oVOfw1qopUA2JJ F8du1frQAMTW7ONDJRVnhOluupIoH4k0lodkUcpLM3Ux92OMdVNP4YWlLOGZ OrQ_AU2hXy4VquFnsg1JO4ysSb3ggi0vtIFYaq9IA0JphMe5keS8f2eFfHBW da_Fau9gVjKZOKtMCmXVNxtT6TbZyGOLzgpTPolUV5pr6enhx3jBEPiujYsW zvkNWkYH1idYCOOBIPNlLmRcInMs.nvn0mZvH8hHI7uSnzjevfcdKrepkdng ueyBWuKVM09vwWddnN6eoxT.yhewJVU9Wgg9EOIluT0vg_g0XvdZcnwOcw8h lUczvUvs6FA-- X-Yahoo-SMTP: V1UR0WuswBDVD1eFhM33188Ir8ciBckz4W8ZMsAh Date: Thu, 15 Sep 2011 13:58:22 +0100 From: Stephane Chazelas To: Peter Stephenson Cc: zsh-users@zsh.org Subject: Re: {fd}< and compound commands Message-ID: <20110915125822.GB5497@yahoo.fr> Mail-Followup-To: Peter Stephenson , zsh-users@zsh.org References: <20110914172148.GA7325@yahoo.fr> <20110914200601.72c91f87@pws-pc.ntlworld.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20110914200601.72c91f87@pws-pc.ntlworld.com> User-Agent: Mutt/1.5.21 (2010-09-15) 2011-09-14 20:06:01 +0100, Peter Stephenson: > On Wed, 14 Sep 2011 18:21:48 +0100 > Stephane Chazelas wrote: > > $ zsh -c '{echo foo >&$fd;} {fd}> a' > > zsh:1: parse error near `{' > > (same for while/do/done constructs at least) > > > > Is that the expected behavior? I can't see it being documented. > > It is documented now. This is all complicated stuff with wide > implications for the parser; there's is no chance I will have to time to > change it myself. > > > That would be useful in > > > > while read <&$fd var; do > > ... > > done {fd}< file > > > > to avoid having to worry about overriding fds 3-9. > > There's no code automatically to close file descriptors anyway. > Generally, that syntax isn't doing quite what the use of redirection > syntax would suggest; it's permanently opening a file descriptor, not > performing a possibly temporary redirection. [...] I just noticed ksh93 doesn't close the fd either, though it supports compound commands: $ ksh93 -c '{ echo test >&$fd; } {fd}> a; echo foo >&$fd; nl a' 1 test 2 foo I suppose those were primarily meant to be used with "exec". Looking at the changelogs for ksh93 and zsh, it seems both shells implemented it within one week of each other (in April 2005), you guys surely must have mentionned it to each other, or does that feature come from another shell/language? KSH> 05-04-08 +Redirection operators can be directly preceded with {varname} KSH> with no intervening space, where varname is a variable name which KSH> allows the shell to select a file descriptor > 10 and store it KSH> into varname. ZSH> 2005-04-12 Peter Stephenson [...] ZSH> * 21133: Doc/Zsh/redirect.yo, Src/exec.c, Src/parse.c, Src/text.c, ZSH> Src/zsh.h, Test/A04redirect.ztst: New {myfd}> syntax for ZSH> allocating file descriptors. -- Stephane