334
Networking: A Beginner's Guide
To show a specific environment variable, specify the variable as a parameter to
printenv
. For example, to see the environment variable USER, type the following:
[root@ford /root]# printenv USER
Setting Environment Variables
To set an environment variable, use the following format:
[root@ford /root]# variable=value
where variable is the variable name, and value is the value that you want to assign the
variable. For example, to set the environment variable FOO with the value BAR, type
the following:
[root@ford /root]# FOO=BAR
After setting the value, use the export command to finalize it. The format of the
export
command is as follows:
[root@ford /root]# export variable
where variable is the name of the variable. In the example of setting FOO, type the
following:
[root@ford /root]# export FOO
You can combine the steps of setting the environment variable with the export
command, as follows:
[root@ford /root]# export FOO=BAR
If the value of the environment variable you want to set has spaces in it, you need
to surround the variable with quotation marks. For example, to set FOO to "Welcome
to the BAR of FOO," type the following:
[root@ford /root]# export FOO="Welcome to the BAR of FOO."
Clearing Environment Variables
To remove an environment variable, use the unset command:
[root@ford /root]# unset variable
where variable is the name of the variable you want to remove. For example, to remove
the environment variable FOO, type the following:
[root@ford]# unset FOO