/ factorpad.com / tech / linux-essentials / printenv-command.html
An ad-free and cookie-free website.
Beginner
Learn to view and set environment variables at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux printenv Command Summary with Examples (3:37)
Our forty-sixth word, or command to memorize is
printenv
from our category
System.
printenv
allows you to print
environment variables.
-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.
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
.
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
.
Nah, that won't work like that, echo
just took us literally, so we'll tell it to look for the variable with
the $
.
Now using printenv
let's look at the
$PS1
variable which is our command
prompt.
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
.
And last, let's customize our prompt, and give me couple seconds here to do this.
Very good, and as always exit
closes
the terminal window.
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.
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
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.
ps
command,
hit Back.export
and click Next./ factorpad.com / tech / linux-essentials / printenv-command.html
A newly-updated free resource. Connect and refer a friend today.