LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

unset

Remove shell variables or functions

TLDR

Unset variable
$ unset [VARIABLE]
copy
Unset function
$ unset -f [function_name]
copy
Unset multiple variables
$ unset [VAR1] [VAR2]
copy
Unset variable explicitly (not function)
$ unset -v [VARIABLE]
copy

SYNOPSIS

unset [-f] [-v] name ...

DESCRIPTION

unset is a shell builtin that removes variables and function definitions from the current shell environment. By default it removes variables, but with the -f flag it removes function definitions instead.Unsetting a variable removes it completely from the environment, unlike setting it to an empty string which leaves the variable defined but empty. This distinction matters for scripts that check whether a variable exists versus whether it has a value. Unsetting exported variables also removes them from the environment inherited by child processes.Changes made by unset only affect the current shell session. Variables and functions defined in shell startup files like ~/.bashrc will be restored when a new shell session starts. Read-only variables cannot be unset.

PARAMETERS

-f

Unset function.
-v
Unset variable (default).
-n
Unset the nameref variable itself rather than the variable it references.
name
Name(s) to unset.

CAVEATS

Shell builtin (POSIX). Cannot unset readonly variables (returns error). Changes only affect the current shell session. The -n option is a bash extension, not available in all POSIX shells.

HISTORY

unset is a standard shell builtin command for removing variables and functions from the shell environment.

SEE ALSO

export(1), set(1), env(1)

Copied to clipboard
Kai