FactorPad
Build a Better Process

Linux unset Command Summary with Examples

Linux unset allows you to remove variables or functions.
  1. Purpose - Learn what unset is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with unset.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
In this tutorial on Linux unset, 49 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / unset-command.html


An ad-free and cookie-free website.


Intermediate

Learn to remove variables and functions at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux unset Command Summary with Examples (3:22)

Video Script

The Command and Why You Need It

Our forty-ninth word, or command to memorize is unset from our category System.

unset allows you to remove variables or functions.

Common Linux unset Options
-options description
-v Unset a variable
-f Unset a function

Recall from printenv, export and set, we've been working with variables? Well, unset will provide for us an easy way to remove them.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The unset command has 2 options and the argument is the variable name.

Unlike most commands, help is not available with double-dash --help because it's a shell built-in, just like export and set, so on most systems documentation hides in the manual page for bash (man bash).

The -v option, the default, removes variables and -f is for functions.

So why is unset an important command? Well, unset offers a simple way to remove shell and environment variables, plus functions as well. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Let's keep it simple and resurrect what we did for printenv and export, except this time do it in one step. Recall, we made a variable called BBTEAM, for baseball team, and set the value to my favorite, the San Francisco Giants, and here's how we'll do it in one step.

$ export BBTEAM=Giants

And then now, test it with printenv BBTEAM. All set.

$ printenv BBTEAM Giants

Then we'll remove it using unset BBTEAM

$ unset BBTEAM

And last, test it with another printenv BBTEAM.

$ printenv BBTEAM $ _

Very good.

A Final Tip

Okay now you know how to use unset. And you know the syntax for commands, options and arguments.

One last tip about the unset command. So this ends a mini-set of videos on variables, next we'll shift gears and talk about resources. That sounds fun, doesn't it?

Okay, thanks for visiting today. I hope this was a helpful introduction to the unset command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

We have fun with Linux on our YouTube Channel, please join us by subscribing there and following @factorpad on Twitter for introductions to new content.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / unset-command.html


linux unset command
unset linux
linux unset
unix unset
unset unix
linux unset examples
unset shell variable
unset environment variable
unset builtin
linux unset environment variable
bash unset
bash unset variable
linux remove variable
linux unset tutorial
linux remove environment variable
shell unset
man unset

A newly-updated free resource. Connect and refer a friend today.