zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Michael Wardle <michael@endbracket.net>, zsh-workers@sunsite.dk
Subject: Re: problem redeclaring path variable (ksh incompatibility)
Date: Thu, 17 Mar 2005 16:50:07 +0000	[thread overview]
Message-ID: <1050317165007.ZM32408@candle.brasslantern.com> (raw)
In-Reply-To: <423994CA.4010609@endbracket.net>

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.


  reply	other threads:[~2005-03-17 16:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-17 14:31 Michael Wardle
2005-03-17 16:50 ` Bart Schaefer [this message]
2005-03-17 17:28   ` Bart Schaefer
2005-03-17 21:42   ` Michael Wardle
2005-03-18  2:42     ` Bart Schaefer
2005-03-18 10:52   ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1050317165007.ZM32408@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=michael@endbracket.net \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).