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

Re: Bug with unset variables



With some trepidation, let me see if I can try and sum up.

fn() {
   typeset foo
   # foo is regarded as set (in the sense "not unset") here.
}

Other shells would treat foo as unset at that point.

This is a long standing feature of zsh, so the default behaviour
is not going to change.  Almost certainly there was no direct
thought at the time zsh was implemented about the details
of this case, so it was probably  not a formal syntactical
decision.

It is a bug when emulating other shells (although note that there
are plenty of such bugs --- emulation is never complete).  I
said I thought we'd done something about this, but I don't see any
evidence, so I was probably wrong.  There is definitely scope for
improvement.

Given that all shells would treat $foo as an empty string in
the context above, the practical impact is limited to a few
edge cases --- granted that can be infuriating (and more)
when you hit one, so I am not dismissing such cases.  That's why
this issue doesn't often come up despite its long-standing
nature.

For the same reason, that $foo will reliably substitute as
an empty string, I don't see any *overriding* reason for
the behaviour of other shells.  That absolutely doesn't
mean I see no arguments for that behaviour, all of
which I think have now been rehearsed.

Hope that's useful.
pws




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