Greg
Greg

Reputation: 47124

Batch - Echo or Variable Not Working

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?

Upvotes: 83

Views: 282165

Answers (3)

harry mcnamara
harry mcnamara

Reputation: 1

Im new to this but maybe trying semicolon at the end of declaring the variable?

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

Upvotes: -2

Jonathan Stanton
Jonathan Stanton

Reputation: 2630

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

SET VAR=GREG
ECHO %VAR%
PAUSE

Upvotes: 32

tcooc
tcooc

Reputation: 21209

Dont use spaces:

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

Upvotes: 176

Related Questions