Skip to main content

Environment Variables

By default, all variables are environment variables, inherited by child processes.

Environment variables are commonly used to pass configuration information to programs and to configure how programs operate.

You can view all of the current variables with the set command; you'll probably want to pipe the output through more. Environment variables are used by all processes, not just the shell!

Common Environment Variables

Environment VariablePurposeExamples
CDCurrent directory''ECHO %CD%''
TIMECurrent time (HH:MM:SS)''ECHO %TIME%''
DATECurrent date in local format''ECHO %DATE%''
ERRORLEVELThe error code / exit status of the last command executed (note that some commands or programs do not set this variable as expected).''DIR \FileThatDoesNotExist ''\ ''ECHO %ERRORLEVEL%''
PATHA semicolon [;] separated list of directories that will be searched when looking for a command''PATH="$PATH;\SpecialDirectory"''
PROMPTThe prompt presented by the shell.''SET PROMPT=Enter a command: ''\ ''SET PROMPT=PPG ''
RANDOMA random integer (0-32767)ECHO %RANDOM%

Note that the prompt and path programs may also be used to adjust the PROMPT and PATH environment variables, respectively.