The parser has different phases when parsing one line.
Thus, percentage expressions all expand when analyzing a line or block before a line (or any line in a block) is executed.
Thus, at runtime, they can no longer change.
set var=origin echo
He outputs
#1 origin #2 origin #3 new value
As during parsing # 2, it will be expanded to origin before any line of the block is executed. Thus, you can see the new value immediately after the block in # 3.
In contrast, slow expansion expands for each line just before line execution.
setlocal EnableDelayedExpansion set var=origin echo
Exit
#1 origin, origin #2 origin, new value #3 new value, new value
Now in # 2 you see two different extensions for the same variable, since% var% expands when parsing the block, but !var! expands after the execution of the line set var=new value .
Learn more about the parser parser in SO: How are Windows command interpreter scripts (CMD.EXE) handled?
jeb
source share