Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: All functions are equal...or ?
- X-seq: zsh-users 11201
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: All functions are equal...or ?
- Date: Thu, 15 Feb 2007 19:29:37 -0800
- In-reply-to: <20070215.043854.25918985.Meino.Cramer@xxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20070215.043854.25918985.Meino.Cramer@xxxxxx>
On Feb 15, 4:38am, Meino Christian Cramer wrote:
>
> lww () {
[...]
> cmdarray=("${(f)$(whence -pa $1)}")
At this point you have assigned to the global array $cmdarray.
> echo ${#cmdarray} ## 1
> echo ${(F)cmdarray}
> typeset -U cmdarray
"typeset" is equivalent to "local" when it appears within the body
of a function, so now you have created a new local scalar (not array)
which hides the global array. That scalar has the "unique" property,
but that's meaningless for scalars.
If you wanted to apply the "unique" property to the existing global
array, you'd need to do
typeset -g -U cmdarray
> echo ${#cmdarray} ## 2
> echo ${(F)cmdarray}
> cmdarray=(${(o)cmdarray})
Now you've changed the type of the local scalar to array. This would
cause the "unique" property to take effect, except that it's an empty
array (because the existing scalar referenced by ${(o)cmdarray} has
never been assigned a value).
[...]
> }
Does this clear things up? You're always better off declaring your
variables, even though the shell language doesn't require it.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author