# Variable Names Between Called Batch Files

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

root\foo.bat
root\grub\bar.bat


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?

-

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.

-

scope is global/ variable is shared as you say..so 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>
setlocal
set a=99

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

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

C:\DOCUME~1\bob>setlocal

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

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

C:\DOCUME~1\bob>

-