196

I have done this:

$ z() { echo 'hello world'; }

How do I get rid of it?

Micah Elliott
  • 9,600
  • 5
  • 51
  • 54
too much php
  • 88,666
  • 34
  • 128
  • 138

2 Answers2

301
unset -f z

Will unset the function named z. A couple people have answered with:

unset z

but if you have a function and a variable named z only the variable will be unset, not the function.

Robert Gamble
  • 106,424
  • 25
  • 145
  • 137
  • 1
    Note that this applies to [POSIX compliant](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#unset) shells, not just Bash. – Franklin Yu Jan 18 '20 at 07:08
5

In Zsh:

unfunction z

That's another (arguably better) name for unhash -f z or unset -f z and is consistent with the rest of the family of:

  • unset
  • unhash
  • unalias
  • unlimit
  • unsetopt

When in doubt with such things, type un<tab> to see the complete list.

(Slightly related: It's also nice to have functions/aliases like realiases, refunctions, resetopts, reenv, etc to "re-source" respective files, if you've separated/grouped them as such.)

Micah Elliott
  • 9,600
  • 5
  • 51
  • 54