FactorPad
Build a Better Process

Linux export Command Summary with Examples

Linux export allows you to pass environment variables to other processes.
  1. Purpose - Learn what export is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with export.
  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 export, 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 / export-command.html


An ad-free and cookie-free website.


Examples of the Linux export Command

Intermediate

Learn to pass environment variables to processes at the Linux command line.

Video Tutorial

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

Linux export Command Summary with Examples (3:37)

Video Script

The Command and Why You Need It

Our forty-seventh word, or command to memorize is export from our category System.

export allows you to pass environment variables to other processes.

Common Linux export Options
-options description
-p List exported environment variables

Recall from the last video, we viewed and edited an environment variable. Now we'll learn how to set and share one.

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

The export command has only 3 options and the argument is the variable to set for use in other processes, run outside the shell.

Unlike most commands, help is not available with double-dash --help and the -p option is helpful to list all variables exported.

So why is export an important command? Well, especially as we advance, we may collect and pass variables to be used outside the local bash session. 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. Recall from video 46, we used printenv but stopped short of actually establishing environment variables. Let's work on that and create an environment variable called BBTEAM for baseball team and input my favorite team, the San Francisco Giants.

$ BBTEAM=Giants $ _

Next, I can use echo to see if it worked by using $BBTEAM, and the dollar sign $ is required because it's a variable.

$ echo $BBTEAM Giants

So far so good.

Then try printenv BBTEAM. Did the BBTEAM environment variable stick?

$ printenv BBTEAM $ _

No.

Now for the whole reason for this video, type export BBTEAM.

$ export BBTEAM $ _

And then last, verify by trying the printenv BBTEAM again.

$ printenv BBTEAM Giants

And very good.

A Final Tip

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

One last tip about the export command. So if you can't find a manual page for export you're not alone. It's a shell builtin for bash, so you'll find information in the very long manual page for bash. If you're curious.

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

Besides joining us at YouTube and @factorpad on Twitter, perhaps the best way to support ad-free education online is by adding a link to this website on your website.

Outline Back Tip Next

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


linux export command
export linux
linux export
unix export
export unix
linux export examples
export path linux
bash export
linux path
path linux
linux add to path
shell export
linux set path
linux add to path
pass environment variables
linux export tutorial
linux set environment variable
man export
export builtin

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