Setting Environment Variables
Previous  Top  Next

To set an environment variable in Windows NT (or DOS), you would just type


set PATH=C:\WINNT
   
and everybody would be happy. This will not work in Linux where you would have to type


export PATH="/usr/bin"
   
Please note that this only works if you are using the bash shell, different shells have different ways of declaring variables. In bash you could also type:

PATH="/usr/bin"

MYVAR="whuppy"

.... some code ...

export PATH

export MYVAR

which would yield the same result. To clear PATH again, we would type


unset PATH

To extend the PATH variable (which is something you will see quite often) and add the path /opt, simply type


export PATH=$PATH:/opt

Use printenv or set to view all environment variables. $PATH simply evaluates to the current path string and :/opt is just being appended.