FactorPad
Faster Learning Tutorials

Linux export command summary with examples

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.
Paul Alan Davis, CFA, October 25, 2016
Updated: August 2, 2018
In this tutorial, 47 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  / export command


The Linux export command

Intermediate

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

Video Tutorial

Linux export command summary with examples (3:37)

Videos can also be accessed from the YouTube Playlist.

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.

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?

Subscribe to our YouTube Channel to learn more.

  • For the Outline to all 100 tutorials, click Outline.
  • To go back to the printenv command, hit Back.
  • For another intermediate command called set, click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / export command



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