From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6904 invoked from network); 17 Mar 2005 16:50:33 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 17 Mar 2005 16:50:33 -0000 Received: (qmail 35848 invoked from network); 17 Mar 2005 16:50:27 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Mar 2005 16:50:27 -0000 Received: (qmail 895 invoked by alias); 17 Mar 2005 16:50:24 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20998 Received: (qmail 880 invoked from network); 17 Mar 2005 16:50:23 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 17 Mar 2005 16:50:23 -0000 Received: (qmail 35577 invoked from network); 17 Mar 2005 16:50:23 -0000 Received: from vms042pub.verizon.net (206.46.252.42) by a.mx.sunsite.dk with SMTP; 17 Mar 2005 16:50:13 -0000 Received: from candle.brasslantern.com ([4.11.1.68]) by vms042.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IDI0073V9FK3NC2@vms042.mailsrvcs.net> for zsh-workers@sunsite.dk; Thu, 17 Mar 2005 10:50:09 -0600 (CST) 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 j2HGo80g032410; Thu, 17 Mar 2005 08:50:08 -0800 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j2HGo8so032409; Thu, 17 Mar 2005 08:50:08 -0800 Date: Thu, 17 Mar 2005 16:50:07 +0000 From: Bart Schaefer Subject: Re: problem redeclaring path variable (ksh incompatibility) In-reply-to: <423994CA.4010609@endbracket.net> To: Michael Wardle , zsh-workers@sunsite.dk Message-id: <1050317165007.ZM32408@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii References: <423994CA.4010609@endbracket.net> Comments: In reply to Michael Wardle "problem redeclaring path variable (ksh incompatibility)" (Mar 18, 1:31am) 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=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 On Mar 18, 1:31am, Michael Wardle wrote: } } I have a script that uses the identifier "path" local to a function. It } works as intended in bash and all the versions of ksh I've tried it on, } but not in zsh, which gives an error message similar to this: } addpath:typeset:6: path: can't assign initial value for array Zsh does not fully emulate the POSIX shell unless it is invoked under the name "sh". The "emulate" command is not sufficient; it only changes the setopts, not the set of special variables etc. that are predeclared at startup time. Hence the "path" variable exists and is special and may only be overridden locally to a function by using "typeset -h path=...". Try running your test script with ARGV0=sh in the environment and note the difference in behavior. } It turns out that neither "typeset path=" nor "typeset path=value" } create a local scalar, which doesn't meet my expectations. Strangely, } however, "typeset path" does. No, it doesn't. Nowhere in your test script is $path a scalar. zsh% func() { emulate ksh; typeset path ; path=scalar ; typeset path } zsh% func path=(scalar) zsh% If we were going to attempt to change this, the right way would be to add a new option, perhaps called LOCAL_SPECIALS, which would be on by default. "emulate sh" et al. would unset this option. When NO_LOCAL_SPECIALS, the typeset builtin would behave as if the -h option were always present. Other, less desirable approaches might be to tie this behavior to the POSIX_BUILTINS or KSH_TYPESET options. Possibly it should be tied to KSH_TYPESET even if LOCAL_SPECIALS is added.