Batch - Echo or Variable Not Working

WindowsBatch File

Windows Problem Overview


I have this little batch script:

SET @var = "GREG"
ECHO %@var%
PAUSE

When I run it, it prints:

H:\Dynamics>SET @var = "GREG"

H:\Dynamics>ECHO
ECHO is on.

H:\Dynamics>PAUSE
Press any key to continue . . .

Why won't it print the contents of @var? How do I know if @var is even being set?

Windows Solutions


Solution 1 - Windows

Dont use spaces:

SET @var="GREG"
::instead of SET @var = "GREG"
ECHO %@var%
PAUSE

Solution 2 - Windows

Try the following (note that there should not be a space between the VAR, =, and GREG).

SET VAR=GREG
ECHO %VAR%
PAUSE

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGregView Question on Stackoverflow
Solution 1 - WindowstcoocView Answer on Stackoverflow
Solution 2 - WindowsJonathan StantonView Answer on Stackoverflow