bug-bash
[Top][All Lists]
Advanced

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

Re: unset does not remove functions like a[b] unless -f is specified


From: Dale R. Worley
Subject: Re: unset does not remove functions like a[b] unless -f is specified
Date: Tue, 31 Jan 2023 14:33:34 -0500

Emanuele Torre <torreemanuele6@gmail.com> writes:
>     bash-5.1$ a[0] () { echo;}
>     bash-5.1$ unset 'a[0]'

Admittedly, I'm running Bash 5.1.0, but the manual page says:

       fname () compound-command [redirection]
       function fname [()] compound-command [redirection]
              ...in posix mode, fname must  be  a
              valid  shell  name  and  may not be the name of one of the POSIX
              special builtins.  In default mode, a function name can  be  any
              unquoted  shell  word that does not contain $.  ...

So it does seem that a function named "a[0]" is valid in default mode.
(And as long as there is no file named "a0" and nullglob is not enabled
(the default), you don't have to quote the name to have it be the word
that is the argument of the command.  So "unquoted" is true.)

       unset [-fv] [-n] [name ...]
              ...  If no options are
              supplied, each name refers to a variable; if there is  no  vari‐
              able  by that name, a function with that name, if any, is unset.

So taking that text strictly, "unset a[0]" should attempt to remove the
variable a[0], and if it does not exist, attempt to remove the function
a[0] that name.

Whether that change would make Bash more useful is debatable.  It's
possible that changing the documentation to match the code would be more
useful.

Dale



reply via email to

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