Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: checking to see if all variables are defined?
- X-seq: zsh-users 16205
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: checking to see if all variables are defined?
- Date: Tue, 09 Aug 2011 08:40:46 -0700
- In-reply-to: <CADjGqHsgMF=5GN4uP_a4VvXN-8kObv5vgnRkJ=6AFjD4Y_3xbw@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADjGqHsgMF=5GN4uP_a4VvXN-8kObv5vgnRkJ=6AFjD4Y_3xbw@mail.gmail.com>
On Aug 9, 11:09am, TJ Luoma wrote:
}
} Does zsh (or someone on the list) already have a way to check whether
} or not all variables which are referenced in a given file are actually
} defined?
There's no generalized "compile time" mechanism for this because the
shell language is interpreted -- i.e., (1) there is no compilation
[even zcompile is only creating a more efficient representation of
the script, not doing any semantic analysis] and (2) there's no way
to predict the side-effects of "autoload", "source", "eval", etc.
However, you can "setopt NO_UNSET" to have the script fail with an
error if it references at run-time a variable that has never been
defined. "Defined", though, includes "declared with typeset" (or
"local", etc.) so the expansion may still be empty.
Recent versions of zsh also have "setopt WARN_CREATE_GLOBAL" which
alerts you if you create a variable at global scope by assignment
from inside a function scope (use "typeset -g" to explicitly do so
and thereby avoid the warning).
--
Messages sorted by:
Reverse Date,
Date,
Thread,
Author