Why does the following Windows Batch File output Foo followedby Bar, rather than Baz?
Foo
Bar
Baz
@echo off setlocal set _=Foo echo %
The answer to this is the same as the answer to:Weird scope issue in batch file. See there for more details. Basically variable expansion is done at line read time, not at execution time.