Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: checking to see if all variables are defined?



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