Page 1 of 1

How delayed expansion works?

Posted: 13 Jun 2020 06:05
by lockedscope
According the parsing rules (https://stackoverflow.com/questions/409 ... ts/4095133) is following explanation correct?

Code: Select all

set "a=xyz"
echo "a: !a!"

set "b=^!a^!"
echo "b: !b!"
rem Output: "b: !a!" - Only Delayed expansion

echo "b percent: %b%"
rem echo "b percent: !a!" - Percent expansion takes place expands %b% to !a!
rem "b percent: xyz" - Then delayed expansion takes place and expand !a! to xyz
rem Finally echo xyz executes

Re: How delayed expansion works?

Posted: 13 Jun 2020 10:31
by jeb
Hi lockedscope,

yes your eplanation is correct.
Percent expansion is always the first one and can't be suppressed.
Then the for-variables expansion occurs.
And the last expansion can be the delayed expansion, if enabled.

jeb

Re: How delayed expansion works?

Posted: 15 Jun 2020 08:06
by lockedscope
Thanks jeb
jeb wrote:
13 Jun 2020 10:31
Hi lockedscope,

yes your eplanation is correct.
Percent expansion is always the first one and can't be suppressed.
Then the for-variables expansion occurs.
And the last expansion can be the delayed expansion, if enabled.

jeb

Re: How delayed expansion works?

Posted: 15 Jun 2020 16:33
by Aacini
Hi lockedscope,

If you want to review some strange things that can be achieved combining %normal% and !delayed! expansions, then I invite you to review this crazy thread...

Antonio

PS - Remember that several %%expansions%% can be nested via CALL command, but !delayed! expansion happen just once...