bug-bash
[Top][All Lists]
Advanced

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

Re: bug: illegal function name?


From: Robert Elz
Subject: Re: bug: illegal function name?
Date: Mon, 21 Jan 2019 09:26:59 +0700

    Date:        Sun, 20 Jan 2019 16:02:51 -0500
    From:        Chet Ramey <chet.ramey@case.edu>
    Message-ID:  <d0c0f1d2-7fd3-2d8d-de42-d986aa68e9a8@case.edu>

  | You should not ignore the variable names case. The behavior of unset
  | without arguments is to check for a variable first, then optionally
  | check for a function name.

That's fine.

  | The variable name check enforces the
  | restrictions on valid characters that may appear in variable names.

That's fine too, but there is no need to generate an error if the
name cannot be a variable name.   Nothing requires that, posix
just says that *if* the name refers to a variable, it gets unset, there
is no specific syntax (note that in the standard for unset, the "name"
there is a placeholder for a word, not the defined "name" word, which
would be written in a different font).  If the name cannot be a variable,
it also cannot be a variable that is set, and if you are going to allow
unset to unset functions in that case, probably you should always do so.

  | The only guaranteed way to make a POSIX shell unset a function name is to
  | use `unset -f'.

That's true.

  | "If neither -f nor -v is specified, name refers to a variable; if a
  | variable by that name does not exist, it is unspecified whether a function
  | by that name, if any, shall be unset."

And that's fine.   Nothing is questioning what the application really
should do, just what happens when the application (or more likely,
some user at the terminal in this case) does something different.

It is certainly not a standards issue.

  | Where is the inconsistent behavior for `unset -f'? It works whatever
  | the name of the function is when in default mode, and obeys the POSIX
  | restrictions when in posix mode.

I think his point is that if unset "unset f" (no flags) works to unset 
function f, if f is not a (set) variable, then it should work every time
"f" is not a set variable, not only the times when the word "f" happens
to be of the correct syntax to be a variable name, but happens not
to be.

I think that is a good point.

In the NetBSD sh we avoid that issue completely, the only way to
unset a function is with "unset -f", a simple "unset f" only ever
unsets variables.

kre




reply via email to

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