set command (Windows / CMD)
What it does
Display, create, or remove CMD environment variables. Searches for the set command cmd environment variable usually need CMD syntax, practical switches, and notes on how it compares with PowerShell or Linux alternatives. This page covers syntax, common options, and copyable examples for Command Prompt.
Display, create, or remove CMD environment variables.
Syntax
set [variable=[string]] | set /A expression | set /P variable=[prompt]
Common options
| Flag / option | Meaning |
|---|---|
| name=value | Assign an environment variable. |
| name= | Remove an environment variable. |
| /A | Evaluate an arithmetic expression. |
| /P | Read a value from standard input. |
| prefix | List variables beginning with a prefix. |
Practical examples
Set value
set APP_ENV=production
Creates APP_ENV for the current CMD process.
Use value
echo %APP_ENV%
Expands and displays the variable.
Calculate
set /A total=7*6
Stores the integer result 42.
Linux ↔ Windows equivalent
Closest match: export (Linux / bash / sh / zsh). Mark shell variables for inheritance by child processes.
Common mistakes
- Adding spaces around `=` and accidentally changing the variable name or value.
- Expecting set values to persist after the Command Prompt closes.
Related commands
- echoDisplay text or control command echoing in a batch script.
- exportMark shell variables for inheritance by child processes.
- systeminfoDisplay detailed operating system, hardware, boot, memory, and update information.
- systemctlControl and inspect services and other systemd units.
- Get-ServiceRetrieve service controller objects and current service states.
- shutdownShut down, restart, sign out, or schedule power actions.
- dateDisplay or format the system date and time.
- journalctlQuery and follow logs stored by the systemd journal.
FAQ
What does set do in Command Prompt?
Display, create, or remove CMD environment variables.
How do I run set in CMD?
Open Command Prompt and follow `set [variable=[string]] | set /A expression | set /P variable=[prompt]`; quote paths containing spaces.
What is a practical set example in CMD?
Try `set APP_ENV=production` — Creates APP_ENV for the current CMD process.
Can set be used in a batch file?
Yes. Check its exit code and escape CMD metacharacters when input is variable.
Browse the full Linux and Windows command reference to search more bash, CMD, PowerShell, Conda, and GitHub CLI commands.