FactorPad
Build a Better Process

Linux set Command Summary with Examples

Linux 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.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
In this tutorial on Linux set, 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 Tip Next

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


An ad-free and cookie-free website.


Examples of the Linux set Command

Intermediate

Video Tutorial

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

Linux set Command Summary with Examples (3:34)

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.

Common Linux set Options
-options description
--help Print help screen

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.

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. 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 and follow to be a part of our smart group.

Outline Back Tip Next

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


linux set command
set linux
linux set
unix set
set unix
linux set examples
set shell variable
set environment variable
set builtin
linux set environment variable
bash set
bash set variable
linux set tutorial
linux set examples
shell set
bash set command
bash set examples
man set

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