Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I have two batch files, foo.bat and bar.bat, that are located like so:


Let's also say that both files contain a line that sets a variable, like so:

set PWD=%cd%

Now, if foo.bat calls .\grub\bar.bat, will bar.bat override the PWD variable set in foo.bat?

share|improve this question
up vote 1 down vote accepted

I ran an experiment. Changing the environment variable in bar.bat causes it to change in foo.bat. I suppose this was to be expected because environment variables set using the set command (not setx) are scoped to the command session.

share|improve this answer

scope is global/ variable is shared as you to echo you, yes.

also, if you use setx it will work for the next cmd session and future ones because it's in the registry., but set and setx aren't to be compared in discussion of scope. environment variables are generally global. But you can use setlocal in a batch file at the start and the variables set there remain local

C:\DOCUME~1\bob>type n.bat <ENTER>
set a=99

C:\DOCUME~1\bob>echo %a% <ENTER>

C:\DOCUME~1\bob>n <ENTER>


C:\DOCUME~1\bob>set a=99

C:\DOCUME~1\bob>echo %a% <ENTER>

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.