@ECHO OFF
CLS
SET ad =
SET /p ad = Do you want to [A] Allow or [D] Deny?
ECHO "%ad%"
I type A
and press Enter
, and the output I get is:
Do you want to [A] Allow or [D] Deny?
""
Why doesn't it work?
You aren't setting %ad%
. You are setting %ad %
.
Some languages are more picky about whitespace than others. The cmd.exe
script language is one of them – the syntax for setting a variable is set name=value
, and if you add spaces around the =
, they become part of the variable name and value.
If you're writing the script for Windows 7/8 only, I strongly recommend learning PowerShell instead. The language used by cmd.exe is awful.
The command processor in Windows 8 is unchanged from the one in Windows 7, as far as I know
Everything up to the equals sign is part of the variable name. So in this case, your variable name is actually "ad "
without the quotes. You can view current environment variables with the command set
without any parameters - this is very useful for debugging.