unset
Linux · Terminal · reference only
What it does
Removes variables or functions from the current shell, so they stop existing in the session.
Syntax
unset [-fnv] nombre...
Options and parameters
nombreVariable or function to remove.
-vTreats the names as variables; this is the default behaviour.
-fTreats the names as functions.
-nFor a variable reference (nameref), removes the reference and not the value it points to.
Usage examples
MIVAR=hola; unset MIVARCreates a variable and removes it.
unset HTTP_PROXYRemoves a proxy variable from the current session.
unset -f saludarRemoves the saludar function defined in the shell.
echo "${MIVAR:-vacia}"After removing the variable, it prints vacia because it no longer exists.
Notes and common mistakes
- It only affects the current session: for permanent changes edit ~/.bashrc or the file that defines it.
- Setting a variable to empty (VAR=) is not the same as removing it with unset.