Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.)

share|improve this question
All that being said, unfunction would be a nice name for a command :-) – Joey Jun 19 '10 at 18:00
@Johannes Rössel: zsh has it. – Chris Johnsen Jun 19 '10 at 20:57
Hm, indeed. Still, I find PowerShell's way of dealing with all this slightly more intuitive and consistent :-) – Joey Jun 20 '10 at 2:12
up vote 19 down vote accepted

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.

share|improve this answer
that's what i was missing. i'd found the -f parameter in export but hadn't found it in unset. thanks. – quack quixote Jun 19 '10 at 3:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .