FactorPad
Faster Learning Tutorials

Linux unset command summary with examples

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.
Paul Alan Davis, CFA, October 26, 2016
Updated: August 2, 2018
In this tutorial, 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 Next

~/ home  / tech  / linux essentials  / unset command


The Linux unset command

Intermediate

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

Video Tutorial

Linux unset command summary with examples (3:22)

Videos can also be accessed from the YouTube Playlist.

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.

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. Subscribe here.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the set command, hit Back.
  • To learn to dig up details about files and file systems with the stat command, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / unset command



 
 
Keywords:
linux unset command
unset linux
linux unset examples
unset shell variables
unset environment variables
unix unset
remove variable in linux
unset builtin
bash unset
linux unset tutorial
bash unset variable
linux unset environment variable
linux unset functions
remove functions in linux
linux remove variable
built-in unset
shell unset
man unset