From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4459 invoked from network); 17 Mar 2005 14:33:45 -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 14:33:45 -0000 Received: (qmail 52853 invoked from network); 17 Mar 2005 14:33:39 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 17 Mar 2005 14:33:39 -0000 Received: (qmail 863 invoked by alias); 17 Mar 2005 14:33:37 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 20995 Received: (qmail 318 invoked from network); 17 Mar 2005 14:31:56 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 17 Mar 2005 14:31:56 -0000 Received: (qmail 52027 invoked from network); 17 Mar 2005 14:31:56 -0000 Received: from 203-206-238-167.dyn.iinet.net.au (HELO mail.endbracket.net) (203.206.238.167) by a.mx.sunsite.dk with SMTP; 17 Mar 2005 14:31:48 -0000 Received: from [192.168.1.7] (unknown [192.168.1.7]) by mail.endbracket.net (Postfix) with ESMTP id 247813698E for ; Fri, 18 Mar 2005 01:31:42 +1100 (EST) Message-ID: <423994CA.4010609@endbracket.net> Date: Fri, 18 Mar 2005 01:31:38 +1100 From: Michael Wardle User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: zsh-workers@sunsite.dk Subject: problem redeclaring path variable (ksh incompatibility) X-Enigmail-Version: 0.90.0.0 X-Enigmail-Supports: pgp-inline, pgp-mime Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 Hi 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 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. It also came as a bit of a surprise to me that "path" should be declared at all when zsh is emulating sh or ksh, but I don't see a good reason to remove that. A test case follows in case you will consider investigating this problem and modifying zsh to act as bash does: ---------- #!/bin/zsh -p # test case for zsh dynamic scoping of "path" variable # Michael Wardle # invoked using -p to ignore user rc files [ -n "$ZSH_VERSION" ] && emulate ksh # arrays are 0 indexed, etc. set -e # exit on error func() { # create a dynamically scoped variable in function scope # the identifier exists at global scope as an array but is # redeclared here as a scalar #typeset path # this works typeset path="local0" # this doesn't work path="local0" path="$path local1" echo "Inside function, values are:" set -- $path for elem do echo "$elem" done } # create a dynamically scoped variable in global scope typeset -a path #export path # path being exported doesn't matter path[0]=global0 path[1]=global1 # display the globally scoped values echo "Outside function, values are:" set -- ${path[@]} for elem do echo "$elem" done func # test that the globally scoped values are restored echo "Outside function, values are:" set -- ${path[@]} for elem do echo "$elem" done ----------