Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove function definition (unalias equivalent) [duplicate]

Tags:

bash

shell

zsh

I'm currently building a program which adds to the current user's shell depending on the project he's working on, by defining per-project aliases and functions. These aliases and functions may and will certainly have the same name like for instance cdproj, which would cd to the project's root.

I would like to remove previously defined aliases and functions when changing project (before (re)defining aliases and functions for the other project. I know I can remove an alias with unalias in both bash and zsh, but how would I do the same for a function?

like image 421
greg0ire Avatar asked Jul 24 '11 13:07

greg0ire


People also ask

How to remove bash function?

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.

How to unset function in linux?

Each variable or function specified by name shall be unset. If -v is specified, name refers to a variable name and the shell shall unset it and remove it from the environment. Read-only variables cannot be unset. If -f is specified, name refers to a function and the shell shall unset the function definition.

How do I list functions in bash?

Function names and definitions may be listed with the -f option to the declare builtin command (see Bash Builtins). The -F option to declare will list the function names only (and optionally the source file and line number).


1 Answers

unset -f my_function 

will remove (or unset) the function my_function

like image 108
ennuikiller Avatar answered Sep 20 '22 21:09

ennuikiller