Under almost all operating systems, every program runs in a so-called environment, which is defined as a set of environment variables. Each environment variable is a key-value pair in the form of KEY=VALUE.

The environment is used for several purposes:

To read or set an environment variable at a comment prompt, use the SET command.

You can specify environment variables by delimiting the variable name to the left and right with a percent (%) sign. This expression will by dynamically replaced by the command processor with the value of the variable.

For example, to add a new entry to the current list of directories in the PATH variable, you can type

SET PATH=%PATH%;C:\NEWDIR

Using the SETLOCAL command, you can make a local copy of the environment space, the current directory, and the current drive, to make temporary changes. All these settings will be restored with the ENDLOCAL command.