Feb 14

Environmental variables are usually used to store the paths so that you don’t have to remember the complete path. Wouldn’t it be easy to just write %windir% in Run or command prompt to open the folder where Windows is installed? Yes, thats the use of environmental variables. Same applies to Linux platform too, just the difference is that in Linux you need to use $ sign before the variable name.

Linux:

To temporarily set environmental variables for the current session, you should run

export VARIABLENAME=”value”

For example, to set your path as mentioned above, you would type:

export PATH=”/bin:/usr/bin:/usr/sbin:/usr/ucb/bin”

You can set enviornment variable permanently by adding following line in /etc/bashrc :

export VARIABLENAME=/path/to/binary

After adding the line at the end of /etc/bashrc run the following command on the shell :

source .bash_profile

It will make this change permanent.You can check that the enviornment vairable is properly setup by :

echo $VARIABLENAME

Windows:

In Windows, you can check the value of any enviornmental variable by echoing it from the command prompt:

From Windows XP > Start Menu > Run, write “cmd” and press enter. To see the value ot PATH enviornmental variable, you have to write:

echo %PATH%

It will show the value of PATH variable. You can also export the new variables. You can add new enviornmental variables from:

  • Right click on My Computer and select Properties.
  • Go to Advanced Tab
  • Environmental Variables will be found at the bottom

Leave a Reply

You must be logged in to post a comment.