nmh-workers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: nmh 1.8RC2, xlbiff, and $HOME


From: Robert Elz
Subject: Re: nmh 1.8RC2, xlbiff, and $HOME
Date: Wed, 01 Feb 2023 04:02:41 +0700

    Date:        Tue, 31 Jan 2023 18:19:58 +0000
    From:        Ralph Corderoy <ralph@inputplus.co.uk>
    Message-ID:  <20230131181958.1CFB121E5F@orac.inputplus.co.uk>

  | No, one cannot say of an unset HOME that it may be set by accident.

No, but it may have been unset by accident, where the intended value
for mh to use was something different than the pw_dir entry.   No-one
can possibly know in that case, any more than in the case where HOME=''

  | There is no ambiguity over the right course.

There is always ambiguity if you are doing something different than
what is documented to happen.   Users may have expected something different
than you expect.

  | In the same way that seeing ${foo:-bar} instead of
  | ${foo:bar} in sh is a smell.

Nonsense, ${foo:-bar} (rather than ${foo-bar} - a version with just a :
would be a ksh, bash, or zsh extension - but in this case I assume just
a typo)) is the more common thing to use.

It matches the other common usage ${foo} which produces nothing when
foo is unset, or when foo=''   (and "${foo}" produces a null string
in either of those cases).   That a default value is to be used instead
of the empty string doesn't change that at all - explicitly using ${foo-bar}
is a much rarer use case (there are occasions when that's wanted, but
they are not very common).

There is no point comparing what shells do when HOME is unset or "",
whether the same thing in the two cases, or something different (and
seemingly bizarre implementations in unusual cases are often just
because the cases are unusual - don't happen often - and slowing down
the normal case to handle those specially isn't worth the effort).
A shell can do whatever it likes in these cases.   So can nmh.

The question is what is best for nmh - and for that I agree with Ken,
treating an unset HOME and HOME='' differently is a mistake.   All that
is required to make that OK is to document it.   There is never a
need to deliberately make anything an error to satisfy user expectations,
if the user wants a complaint about HOME being an empty string, rather
than some other behaviour, all they need is one of

        test -z "${HOME}" && { echo Error; exit ; }
or
        test -z "${HOME-x}" && { echo Error; exit ; }

(the latter being a case where omitting the ':' is wanted)

My experience is that lots of users don't know "unset" exists in the
shell.   They just do var=  (or unnecessarily var='') when then want a
variable to "go away".   Most of the time unset and empty variables mean
the same thing, so this just works.

kre




reply via email to

[Prev in Thread] Current Thread [Next in Thread]