Skip to main content

Command referenceset

set command (Windows / CMD)

WindowsCMDsystembeginner

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 / optionMeaning
name=valueAssign an environment variable.
name=Remove an environment variable.
/AEvaluate an arithmetic expression.
/PRead a value from standard input.
prefixList 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.

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.