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

Re: More rabbit-holes with unset variables



The original Bourne shell did I believe have both export and the
${...-...} form. Using /bin/sh from Solaris (available for Linux as
heirloom sh):
  export FOO
  echo ${FOO-replacement}
Will output the replacement.

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.

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.

Zsh's behaviour is long-standing - I've even checked 2.5.03. And it is
well-defined behaviour so declaring it a feature is an option.

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

But if we decide to "fix" it for zsh, I don't think it'll break too much.
Given that empty values are rarely especially useful, I've always used
the :- form. If the change sits in git for a reasonable time, we might
find out how much it might break.

I did reply on the initial thread but the References: header hit
a mail server limit for line length and it failed.
So I've covered my main point but just to pick out something from this
thread:

Felipe Contreras wrote:
> The discussion is about what "typeset var" (with no type) should do.

That is not "with no type", it has the default type which effectively is
a string. Other shells also treat such variables as an empty string for
the purposes of other features. Try += for example.

Oliver




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