From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17491 invoked from network); 6 Jun 2005 04:15:11 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 6 Jun 2005 04:15:11 -0000 Received: (qmail 88786 invoked from network); 6 Jun 2005 04:15:05 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 Jun 2005 04:15:05 -0000 Received: (qmail 18795 invoked by alias); 6 Jun 2005 04:14:57 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8953 Received: (qmail 18784 invoked from network); 6 Jun 2005 04:14:56 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 6 Jun 2005 04:14:56 -0000 Received: (qmail 87373 invoked from network); 6 Jun 2005 04:14:56 -0000 Received: from vms040pub.verizon.net (206.46.252.40) by a.mx.sunsite.dk with SMTP; 6 Jun 2005 04:14:52 -0000 Received: from candle.brasslantern.com ([4.11.1.68]) by vms040.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IHN0004YAGQJA80@vms040.mailsrvcs.net> for zsh-users@sunsite.dk; Sun, 05 Jun 2005 23:14:51 -0500 (CDT) Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id j564EnoC021456 for ; Sun, 05 Jun 2005 21:14:49 -0700 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j564EnJS021455 for zsh-users@sunsite.dk; Sun, 05 Jun 2005 21:14:49 -0700 Date: Mon, 06 Jun 2005 04:14:49 +0000 From: Bart Schaefer Subject: Re: Function definitions In-reply-to: <20050606.052350.41178724.Meino.Cramer@gmx.de> To: zsh-users@sunsite.dk Message-id: <1050606041449.ZM21454@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii References: <20050606.052350.41178724.Meino.Cramer@gmx.de> Comments: In reply to Meino Christian Cramer "Function definitions" (Jun 6, 5:23am) X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 On Jun 6, 5:23am, Meino Christian Cramer wrote: > > Is there any difference in defining functions like In zsh there is no difference whether you use the "function" keyword or not, but in ksh the variable scoping rules are different for definitions that use it. So be careful if you have any intention of porting. I prefer to use "function" because it avoids problems with function and alias names clashing. However: > function fnord(){ > fnord(){ Those two are OK and do what you expect, but you should get used to putting spaces before the empty parens and before the open-brace, because even though zsh does not always enforce it, the grammar does say that the spaces should be there, and it's crucial to this next example: > function fnord{ That defines a function named "fnord{" whose body will consist of the next single command seen (*not* up to a matching close-brace). If you add a space ... function fnord { ... then *that* does what you meant. > fnord{ This is a *call* to the function named "fnord{". Even with a space ... fnord { ... is not a definition, it's a *call* to the "fnord" function with the argument "{". You must have either the keyword "function" or the empty parens to make a definition. I believe using both is a syntax error in ksh, although zsh allows it. > (In 'man zshall' I found nothing appropiate...) In the COMPLEX COMMANDS section: function word ... [ () ] [ term ] { list } word ... () [ term ] { list } word ... () [ term ] command where term is one or more newline or ;. Define a function which is referenced by any one of word.