How do I unset or get rid of a bash function?

If you set or export an environment variable in bash, you can unset it. If you set an alias in bash, you can unalias it. But there doesn't seem to be an unfunction.

Consider this (trivial) bash function, for example, set in a .bash_aliases file and read at shell initialization.

function foo () { echo "bar" ; }

How can I clear this function definition from my current shell?
(Changing the initialization files or restarting the shell doesn't count.)


The unset built-in command takes an option, -f, to delete functions:

unset -f foo

Form the unset entry in the bash manpage:

If -f is specified, each name refers to a shell function, and the function definition is removed.

Note: -f is only really necessary if a variable with the same name exists. If you do not also have a variable named foo, then unset foo will delete the function.


See help unset:

unset: unset [-f] [-v] [-n] [name ...]

Unset values and attributes of shell variables and functions.

For each NAME, remove the corresponding variable or function.

Options:
  -f    treat each NAME as a shell function
  -v    treat each NAME as a shell variable
  -n    treat each NAME as a name reference and unset the variable itself
    rather than the variable it references

Without options, unset first tries to unset a variable, and if that fails,
tries to unset a function.

Some variables cannot be unset; also see `readonly'.

Exit Status:
Returns success unless an invalid option is given or a NAME is read-only.

There is neither unset --help nor man unset unfortunately.