Using SET to set an empty value to a variable works nicely in a Windows XP .CMD script. However, the same SET command behaves differently in the same CMD interpreter when used directly from command-line:
Trying to test it in a CMD.EXE command-line:
C:\>set Q=
C:\>echo %Q%
%Q%
C:\>echo "%Q%"
"%Q%"
C:\>set Q=/Q
C:\>echo %Q%
/Q
C:\>echo "%Q%"
"/Q"
Trying to test it with a .CMD script like this:
set Q=
echo %Q%
echo "%Q%"
set Q=/Q
echo %Q%
echo "%Q%"
Running it:
C:\>c.cmd
C:\>set Q=
C:\>echo
ECHO is on.
C:\>echo ""
""
C:\>set Q=/Q
C:\>echo /Q
/Q
C:\>echo "/Q"
"/Q"
What am I missing?
Is that a nice joke from Redmond, or is there any sane explanation for this difference?
How am I supposed to test lines from a .CMD script when they behave differently when used in a command-line?
How do I properly set a variable to an empty string value in a CMD command-line and how do I reference that variable so that I get that empty string?
set
changed its behaviour or theecho
did since Windows XP. IsQ
variable listed when you runset
? – Vlastimil Ovčáčík Dec 22 '13 at 15:02SET
deletes the variable when issued from the command line. It does not delete the variable when used in a .CMD file. – Laszlo Valko Dec 22 '13 at 18:56set Q=
command deletes the variable in both scenarios. – Vlastimil Ovčáčík Dec 22 '13 at 21:37