How do I update and display an environment variable?
Author: Deron Eriksson
Description: This Linux tutorial demonstrates how to update and display an environment variable.
Tutorial created using: CentOS release 4.6


The value of an environment variable can be referenced by preceding the variable name by a dollar sign. Thus, we can use the "echo" command followed by a dollar-sign-preceded environment variable to display the value of that variable.

As an example, we can display the value of the PATH variable via the following command:

echo $PATH

We can set the value of an environment variable by simply following its name by an equal sign followed by the new value. The value on the right can be the previous value of the environment variable, which can be referenced by preceding the environment variable name with a dollar sign.

This is demonstrated below. The following command adds the "/etc" directory to the current PATH environment variable.

PATH=$PATH:/etc

Here, we can see the value of the PATH environment variable before and after we update its value. We display PATH's value via "echo $PATH".

updating and displaying PATH environment variable