From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4631 invoked by alias); 27 Oct 2010 12:50:55 -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: 28377 Received: (qmail 4056 invoked from network); 27 Oct 2010 12:50:53 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at csr.com does not designate permitted sender hosts) Date: Wed, 27 Oct 2010 13:49:00 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: PATCH: document more alias problems Message-ID: <20101027134900.48001ac2@pwslap01u.europe.root.pri> In-Reply-To: <87k4l34yfb.fsf@gmail.com> References: <4BF51CF3.8010609@kth.se> <4CC7EB88.8020105@kth.se> <20101027110240.16941d1f@pwslap01u.europe.root.pri> <4CC801C1.1020109@kth.se> <20101027114840.2e586852@pwslap01u.europe.root.pri> <87k4l34yfb.fsf@gmail.com> Organization: Cambridge Silicon Radio X-Mailer: Claws Mail 3.7.6 (GTK+ 2.18.9; i686-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 27 Oct 2010 12:49:00.0999 (UTC) FILETIME=[541EF570:01CB75D5] X-Scanned-By: MailControl A-06-00-00 (www.mailcontrol.com) on 10.71.0.124 While I'm at it, it's probably high time that another note on alias problems was promoted to the manual. It's been in the FAQ for a while but it could do with highlighting since it's really annoying and confusing if you come across it. Index: Doc/Zsh/grammar.yo =================================================================== RCS file: /cvsroot/zsh/zsh/Doc/Zsh/grammar.yo,v retrieving revision 1.20 diff -p -u -r1.20 grammar.yo --- Doc/Zsh/grammar.yo 27 Oct 2010 12:29:13 -0000 1.20 +++ Doc/Zsh/grammar.yo 27 Oct 2010 12:45:19 -0000 @@ -500,6 +500,27 @@ is too late to expand the newly defined a problem in shell scripts, functions, and code executed with `tt(source)' or `tt(.)'. Consequently, use of functions rather than aliases is recommended in non-interactive code. + +Note also the unhelpful interaction of aliases and function definitions: + +example(alias func='noglob func' +func+LPAR()RPAR() { + echo Do something with $* +}) + +Because aliases are expanded in function definitions, this causes the +following command to be executed: + +example(noglob func+LPAR()RPAR() { + echo Do something with $* +}) + +which defines tt(noglob) as well as tt(func) as functions with the +body given. To avoid this, either quote the name tt(func) or use the +alternative function definition form `tt(function func)'. Ensuring the +alias is defined after the function works but is problematic if the +code fragment might be re-executed. + texinode(Quoting)()(Aliasing)(Shell Grammar) sect(Quoting) cindex(quoting) -- Peter Stephenson Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom