Declaring and using a variable in a Windows batch file (.BAT)

advertisements

I'm trying to declare and use a variable in my batch file. It looks like it should be simple.

@ECHO OFF

SET location = "bob"
ECHO We're working with "%location%"

The output I get is:

We're working with ""

What's going on here? Why is my variable not being echo'd?


The space before the = is interpreted as part of the name, and the space after it (as well as the quotation marks) are interpreted as part of the value. So the variable you’ve created can be referenced with %location %. If that’s not what you want, remove the extra space(s) in the definition.