FactorPad
Build a Better Process

Linux printenv Command Summary with Examples

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

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


An ad-free and cookie-free website.


Examples of the Linux printenv Command

Beginner

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

Video Tutorial

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

Linux printenv Command Summary with Examples (3:37)

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.

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

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?

Have a look around and I think you'll see this is a site entirely devoted to advancing your data analysis career. Connect now before distractions take your focus away.

Outline Back Tip Next

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


linux printenv command
printenv linux
linux printenv
unix printenv
printenv unix
linux printenv examples
print environment variables
linux environment
linux set environment variable
linux environment variables
export path
environment variables
linux path
path linux
shell variable
linux printenv tutorial
linux systesm variables
linux show environment variables
echo environment variables
man printenv

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