From: "Bart Schaefer" <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Re: Bug/Caveat for local variables in functions
Date: Tue, 31 Dec 2002 04:02:36 +0000 [thread overview]
Message-ID: <1021231040236.ZM25275@candle.brasslantern.com> (raw)
In-Reply-To: <OF0E547989.924C9F53-ONCA256CA0.000A2D50@mlc.com.au>
On Dec 31, 12:54pm, tim_smithers@mlc.com.au wrote:
}
} You can't create a local variable with the same name as a special var.
Yes, you can. Yout just have to tell zsh to make the local non-special.
testit()
{
local -h path=foo
echo $path
}
} testit()
} {
} local path=foo
} echo $path
} }
}
} this echo's your path, not 'foo'. You don't get any warnings about the
} assignment not working etc.
What version of zsh do you have? Without the -h option, I get this:
testit:local:2: path: can't assign initial value for array
} The main reason I found it was porting some shell which works in ksh and
} bash to zsh compliant (which has a "path" variable).
Usually the quickest way to do this is just to place
emulate -L sh
at the top of the script. If you're really _porting_ to native zsh mode,
rather than wanting to have zsh execute a Bourne shell script, then you
may have a lot more changes to make than just adding -h to locals. For
example, you're probably also going to have to change variable references
from $VAR to $=VAR (when not quoted), to get sh-style word splitting.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
prev parent reply other threads:[~2002-12-31 4:03 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-12-31 1:54 tim_smithers
2002-12-31 4:02 ` Bart Schaefer [this message]
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=1021231040236.ZM25275@candle.brasslantern.com \
--to=schaefer@brasslantern.com \
--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).