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

  • nombre

    Variable or function to remove.

  • -v

    Treats the names as variables; this is the default behaviour.

  • -f

    Treats the names as functions.

  • -n

    For a variable reference (nameref), removes the reference and not the value it points to.

Usage examples

  • MIVAR=hola; unset MIVAR

    Creates a variable and removes it.

  • unset HTTP_PROXY

    Removes a proxy variable from the current session.

  • unset -f saludar

    Removes 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.

Related commands