Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 10 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.