Faster Learning Tutorials

Linux set command summary with examples

set allows you to display or set shell and environment variables.
  1. Purpose - Learn what set is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with set.
  4. A tip - Finish off with one more insight.
Paul Alan Davis, CFA, October 26, 2016
Updated: August 2, 2018
In this tutorial, 48 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  / set command

The Linux set command


Video Tutorial

Linux set command summary with examples (3:34)

Videos can also be accessed from the YouTube Playlist.

Video Script

The Command and Why You Need It

Our forty-eighth word, or command to memorize is set from our category System.

set allows you to display or set shell and environment variables.

Recall from the printenv and export videos, we saw environment variables? Well, set tacks on variables unique to a shell program, like bash.

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

This fairly advanced set command has over 20 options which we won't cover here and the argument is the variable and value.

Unlike most commands, help is not available with double-dash --help because as a shell built-in, documentation sits in the bash manual page (man bash).

So why is set an important command? Well, in some situations you may need to set and unset shell variables and functions. And now you know how to do that.


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. So I mainly wanted to introduce you to set as a way to understand that there are environment variables, shell variables and a new concept called functions. So instead of our regular demonstration, this will be homework. So follow these steps.

First, enter printenv optionless, like you did in video 46. Then type set optionless and compare.

$ printenv > video48a.txt; set > video48b.txt $ _

Output from set will be long, so use Shift-PgUp and Shift-PgDn right here in the terminal, or write it to a file using the redirection symbol > and then just take 5 minutes to zip through it with less.

And last, functions on the output can be identified by curly braces { } and if then.

A Final Tip

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

One last tip about the set command. So here I simply wanted you to see what's passed around behind the innocent-looking terminal window. Don't worry, the next few videos will be easier.

Okay, thanks for visiting today. I hope this was a helpful introduction to the set 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?

Not only will you find homework on our YouTube Channel, but also quizzes! Subscribe here.

  • For the Outline to all 100 tutorials, click Outline
  • To go back to the export command, hit Back.
  • To get a little more practice with the unset command, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / set command

linux set command
set linux
linux set examples
set shell variables
unix set
set environment variables
set builtin
bash set
linux set
bash set examples
shell set variable
bash set variable
linux set environment variable
man set
linux set functions
bash set command
linux set tutorial
built-in set