Windows environment variables store values that programs use for configuration, such as the current username, temporary-file location, and folders searched when you run commands. To view the value of one environment variable in Command Prompt (CMD), type echo %VARIABLE_NAME%. For example, echo %PATH% shows the effective PATH available to your current CMD process.
Quick answer: Display one variable in CMD
- Press Windows + R, enter cmd, and press Enter. You can also open Command Prompt through Windows Search.
- To display your current user name, type
echo %USERNAME%and press Enter. - For a different variable, replace
USERNAMEwith the variable name, keeping the % signs around it.
echo %USERNAME%
echo %USERPROFILE%
echo %TEMP%
echo %PATH%In CMD, environment variable names are not case-sensitive. Thus %PATH% and %path% refer to the same variable in a normal Windows environment. The values above are examples of the current process environment, so they can differ by user account or Command Prompt window.
Display all environment variables with SET
Use set without arguments to print the environment variables visible to the current Command Prompt process. This can be helpful when debugging an application’s configuration, but the output may contain private paths, account identifiers, or credentials. Do not paste the unredacted result into a public forum or ticket.
setTo view variables whose names begin with a prefix, use the prefix as an argument:
set USER
set JAVA
set PATHFor example, set JAVA can display JAVA_HOME if it exists. It can also show multiple matching names or report that no variable starts with that prefix. Microsoft’s SET command reference describes both listing and setting variables.
Check whether a variable is defined
If echo %VARIABLE_NAME% prints the literal percent-sign expression, the variable is usually undefined in that CMD session. Use set VARIABLE_NAME to check. Unlike echo, the set command can report that the variable is not defined; a prefix search can also return similarly named variables. Do not assume that a variable saved in Windows settings has propagated into an already-open terminal.
set JAVA_HOMEIf you are troubleshooting Java or another development tool, remember that setting JAVA_HOME is not the same as adding its executable folder to PATH. One can be correct while the other is missing.
CMD vs PowerShell: the syntax is different
In Windows PowerShell or PowerShell 7, environment variables use env:USERNAME
env:PATH
Get-ChildItem Env:
The last command lists environment variables accessible through PowerShell’s Env: drive. For more details, see Microsoft Learn: PowerShell environment variables.
Display PATH in a readable way
Windows PATH usually contains several directories separated by semicolons. To inspect them individually in PowerShell, split the current PATH on semicolons:
.env:VARIABLE_NAME
Why does the value differ from Environment Variables in Settings? CMD reads its process environment, which may include temporary changes and may not reflect a registry change made after that window opened.
Why are my Java or Python commands not recognized? Check both the related installation path and the
PATHvariable. A correct environment variable alone does not guarantee that every program has restarted or can find the executable.Can I display variables in a batch file? Yes. A
.bator.cmdscript can useecho %PATH%andset. Be aware that percent expansion in loops and parenthesized blocks has additional timing rules; use delayed expansion intentionally if needed.Summary
Use
echo %NAME%to see one value in CMD,setto list the current environment, and$env:NAMEin PowerShell. When troubleshooting, open the right shell, verify which user or process you are in, and avoid sharing sensitive environment-variable values.For more Windows command-line context, read our article on Windows drive letters.
C P Gupta is a YouTuber and Blogger. He is expert in Microsoft Word, Excel and PowerPoint. His YouTube channel @pickupbrain is very popular and has crossed 9.9 Million Views.
