Variables not setting in Windows batch file?

Windows batch files (.bat) can be scripted, which means you can do all sorts of things like setting variables. But if you’re having a hard time getting those variables to set, this might be why.

SET var=Holy crap, it sets the variable!

Will work fine, but…

SET var = Holy crap, the space screws it up!

… will not. If you’re used to putting spaces after equals signs like I am, you can make this mistake without even knowing it. If you do it wrong, it won’t throw any errors either. Just silently fails.

Leave a Comment

Your email address will not be published.