Getting and setting environment variables
One of the best environment variables editors for Windows is Eveditor. It provides a solution to problem of editing environment variables by allowing to modify them in interactive and friendly manner. It automatically splits the Path variable into a list of locations, manages both system and user settings at the same time, does the validation of variable values and so on.
The tool is free and can be downloaded from the official site. This is recommended way of managing environment variables.
For use in scripts and on the command line the
set command can be utilized. Without any arguments it displays all environment variables along with their values.
To set an environment variable to a particular value, use:
However, this is temporary. Permanent change to the environment variable can be achieved through editing the registry (not recommended for novices) and using the Windows Resource Kit application
setx.exe. With the introduction of Windows Vista, the
setx command became part of Windows.
Users of the Windows GUI can manipulate variables via <Control Panel:System:Advanced:Environment Variables>; through the Windows Registry this is done changing the values under HKCU\Environment (for user specific variables) and HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment (for System variables).
To display the current value of an environment variable, use:
Note: Please take note that doing so will print out all variables beginning with 'VARIABLE'.
Another example that displays all environment variables beginning with 'p':
C:\> set p Path=c:\.. .. PATHEXT=.COM;.EXE;.BAT; PROCESSOR_ARCHITECTURE=.. .. PROCESSOR_IDENTIFIER=x8.. PROCESSOR_LEVEL=6.. PROCESSOR_REVISION=1706.. ProgramFiles=C:\Program.. . PROMPT=$P$G
To delete a variable, the following command is used:
The commands env, set, and printenv display all environment variables and their values. env and set are also used to set environment variables and are often incorporated directly into the shell. printenv can also be used to print a single variable by giving that variable name as the sole argument to the command.
A few simple principles govern how environment variables BY INSTALLING, achieve their effect:
- Environment variables are local to the process in which they were set. That means if we open two terminal windows (Two different processes running shell) and change value of environment variable in one window, that change will not be seen by other window.
- When Parent process creates a child process, the child process inherits all the environment variable and their values which parent process had.
- The names of environment variables are case sensitive.
- Environment variables persistence can be session-wide or system-wide.