I am trying to learn MS Batch, and I was specifically trying to understand the "setlocal" and the "enabledelayedexpression" aspects, when I came across vocabulary I did not understand:
execution time and parse time
I am trying to learn MS Batch, and I was specifically trying to understand the "setlocal" and the "enabledelayedexpression" aspects, when I came across vocabulary I did not understand:
execution time and parse time
The parser has different phases, when parsing a single line.
So the percent expressions are all expand when a line or block is parsed, before the line (or any line in a block) is executed.
So at execution time they can't change anymore.
It outputs
As at parse time #2 will be expanded to
origin
before any line of the block is executed. So you can see the new value just after the block at #3.In contrast, delayed expansion is expanded for each line just before the line is executed.
Output
Now at #2 you see two different expansions for the same variable, as %var% is expanded when the block is parsed, but
!var!
is expanded after the lineset var=new value
was executed.More details about the batch parser at SO: How does the Windows Command Interpreter (CMD.EXE) parse scripts?