The environment variables are used by the shell and its child processes for normal execution of the programs. However, there are times when there is a need to add new variables for specific applications to work. First of all, check the environment parameters with ‘env’ command as shown below:

image

To add the parameter simply use the new parameter name and assign it a value. Lets say, we want to add a parameter called ‘NEWPARAM’ to the environment, first define the parameter as follows:

linux:~ #
linux:~ # NEWPARA=’test’
linux:~ #

The parameter has been defined but is it in the set of environment parameters? Lets search it in our environment

linux:~ #
linux:~ # env | grep NEWPARA
linux:~ #

As you can see, it yields nothing. So, lets see if we can see our new parameter with ‘echo’ or not?

linux:~ #
linux:~ # echo $NEWPARA
test
linux:~ #

The new parameter is defined but it has not been added to environment parameters yet. To do so, we use ‘export’ command. Now, lets add it and see the results.

linux:~ # export NEWPARA
linux:~ #
linux:~ # env | grep NEWPARA
NEWPARA=test
linux:~ #

As you can see, now the environment does contain our new parameter.

Adnan Khurshid

Adnan Khurshid, the author of this article, has been working in a telecommunication sector since 2007. He has worked there as a VAS (Value Added Services) engineer and has excelled remarkably in the field. Working in this field has been his passion and he has always made efforts to keep himself up to date. Find more about him on LinkedIn

More Posts

Tags: , ,

1 Comment on How to add environment variables in Linux/Unix

  1. […] on how to set the environment variables in Linux/Unix system. You may want to have a look it here. Let’s see how we can delete the variables in the SUN Solaris system. The “env” command will […]

Leave a Reply