0% found this document useful (0 votes)
50 views2 pages

2014 02-26-21!40!20 Environment Variables Text

Environment variables store information that can affect how programs behave. Common environment variables include EDITOR, HOME, PATH, and USER. The env and printenv commands can be used to view all environment variables or a specific variable. Exporting a variable makes it available to child processes, while unset removes a variable from the environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views2 pages

2014 02-26-21!40!20 Environment Variables Text

Environment variables store information that can affect how programs behave. Common environment variables include EDITOR, HOME, PATH, and USER. The env and printenv commands can be used to view all environment variables or a specific variable. Exporting a variable makes it available to child processes, while unset removes a variable from the environment.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Environment Variables

You have already been introduced to environment variables and have put them to good use. To
recap, an environment variable is a storage location that has a name and a value. They often
effect the way programs behave. For example, you learned how to inform various programs about
your preferred editor by defining the $EDITOR environment variable.
Common Environment Variables

Variable

Description

EDITOR
HOME
LOGNAME
MAIL
OLDPWD
PATH
PAGER
PS1
PWD
USER

The program to run to perform edits.


The Home directory of the user.
The login name of the user.
The location of the user's local inbox.
The previous working directory.
A colon separated list of directories to search for commands.
This program may be called to view a file.
The primary prompt string.
The present working directory.
The username of the user.

Viewing Environment Variables

If you know the name of the environment variable that you want to examine, you can run echo
$VARIABLE_NAME or printenv VARIABLE_NAME . If you want to examine all the environment
variables that are set, use the env or printenv commands.
printenv

- Print all or part of environment.

$ printenv HOME
/home/bob
$ echo $HOME
/home/bob
$ printenv
TERM=xterm-256color
SHELL=/bin/bash
USER=bob
PATH=/usr/local/bin:/usr/bin:/bin
MAIL=/var/mail/bob
PWD=/home/bob
LANG=en_US.UTF-8
HOME=/home/bob
LOGNAME=bob
$ env
TERM=xterm-256color
SHELL=/bin/bash
USER=bob
PATH=/usr/local/bin:/usr/bin:/bin
MAIL=/var/mail/bob
PWD=/home/bob
LANG=en_US.UTF-8
HOME=/home/bob
LOGNAME=bob
$
Exporting Environment Variables

When a process is started it inherits the exported environment variables of the process that
spawned it. A variable that is set or changed only effects the current running process unless it is
exported. The variables that are not exported are called local variables. The export command
allows variables to be used by subsequently executed commands. Here is an example.
$ echo $PAGER
$ PAGER=less
$ echo $PAGER
less
$ bash
$ echo $PAGER
$ exit
exit
$ export PAGER=less
$ bash
$ echo $PAGER
less
$ exit
exit
$

In the above example PAGER was defined in the current environment. When you start a child
process it inherits all the environment variables that were exported in your current environment.
Since PAGER was not exported it was not set in the spawned bash shell. When you exported
PAGER you saw that it was indeed available in the child process.

Removing Variables from the Environment


You can use unset to remove or delete an environment variable.
$ echo $PAGER
less
$ unset PAGER
$ echo $PAGER
$

http://www.LinuxTrainingAcademy.com

You might also like