FactorPad
Faster Learning Tutorials

Linux printenv command summary with examples

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


The Linux printenv command

Beginner

Learn to view and set environment variables at the Linux command line.

Video Tutorial

Linux printenv 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-sixth word, or command to memorize is printenv from our category System.

printenv allows you to print environment variables.

Recall from video 19, we used echo to print the PATH, and said we'd come back and talk about environment variables, well it's time.

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

The printenv command has only 3 options and the arguments are the variables you'd like to print, or enter none to see all of them.

Like most commands, help is available with double-dash --help.

So why is printenv an important command? Well, we need to understand the environment. 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 we used the $ symbol with echo to view variables and the = to set them. To refresh your memory something=Linux.

$ something=Linux $ echo "I'm here to learn $something" I'm here to learn Linux

And "I'm here to learn dollar sign $something". Good.

Next, try printing the location of your current working directory, which is an environment variable, echo PWD.

$ echo PWD PWD

Nah, that won't work like that, echo just took us literally, so we'll tell it to look for the variable with the $.

$ echo $PWD /home/paul

Now using printenv let's look at the $PS1 variable which is our command prompt.

$ printenv $PS1 $ _

And woops, printenv doesn't work like that, so let's try PS1, and while we're at it, let's add our language LANG and working directory PWD.

$ printenv PS1 LANG PWD \n $ en_US.UTF-8 /home/paul

And last, let's customize our prompt, and give me couple seconds here to do this.

$ PS1="What would you like to do next? " What would you like to do next? exit

Very good, and as always exit closes the terminal window.

A Final Tip

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

One last tip about the printenv command. So why don't you try a printenv without options or arguments on your end and see how many variables you can decipher. Treat it like a progress check for your knowledge.

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

Click here to join our growing YouTube Channel.

  • For the Outline to all 100 tutorials, click Outline
  • To go back to the ps command, hit Back.
  • Environment variables are a difficult concept for most, stick with it in the next tutorial on export and click Next.

Outline Back Next

~/ home  / tech  / linux essentials  / printenv command



 
 
Keywords:
linux printenv command
printenv linux
linux printenv examples
printenv unix
print environment variables
linux environment
linux set environment
linux environment variables
export path
environment variables
linux path
shell variable
linux printenv tutorial
linux printenv syntax
linux system variables
linux show environment variables
echo environment variables
man printenv