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

Re: More rabbit-holes with unset variables

On Thu, Nov 26, 2020 at 3:22 AM Oliver Kiddle <opk@xxxxxxx> wrote:
> It appears that export VAR will not export an empty VAR even in zsh
> (unless you do VAR=""). So zsh's not exactly consistent.
> typeset [-x] is arguably just a variant of export.

Neither is a variant of the other; "export" is an alias for "typeset
-xg" that happens to be implemented as a reserved word.

> This does change how I regard zsh's behaviour. It isn't zsh taking a
> different but equally valid approach on an extension but an sh
> incompatibility. It once was a bug even if now too entrenched.

It doesn't export the empty string at the time the parameter is
declared, but it does consistently set it to empty string internally:

% Src/zsh -f
% export FOOBAR
% typeset -p FOOBAR
export FOOBAR=''

If it were NOT set, as after "unset FOOBAR", then "typeset -p" would
print nothing.

> It does make the KSH_TYPESET option somewhat less appropriate because
> this effect also applies to sh emulation.

We could do this when EMULATION(EMULATE_KSH|EMULATE_SH) instead of on an option.

If we are in fact limiting it to variables with no "strong type" type
then it really is sufficient to create an unset variable, except that
we somehow have to signal to "typeset -p" that it should print the
declaration even though the variable appears to be unset.

The latter raises the question of whether we want the Bash behavior of
continuing to print the declaration even after an explicit "unset",
which differs from ksh (cf. my first message in this thread).

Messages sorted by: Reverse Date, Date, Thread, Author