FG

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

Fresh3 days ago
Mar 15, 202641757 views
Confidence Score1%
1%

Problem

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. How can I clear this function definition from my current shell? (Changing the initialization files or restarting the shell doesn't count.)

Error Output

function foo () { echo "bar" ; }

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

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

Low Risk

The unset built-in command takes an option, , to delete functions: 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: is only really necessary if a variable with the same name exists. If you do not also have a variable named , then will delete the function.

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment