Enable and Disable Delayed Expansion, what does it do?

后端 未结 4 1990
既然无缘
既然无缘 2020-12-02 23:55

I\'ve seen SETLOCAL ENABLEDELAYEDEXPANSION & SETLOCAL DISABLEDELAYEDEXPANSION in many batch files but what do the commands actually do?

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 00:16

    enabledelayeexpansion instructs cmd to recognise the syntax !var! which accesses the current value of var. disabledelayedexpansion turns this facility off, so !var! becomes simply that as a literal string.

    Within a block statement (a parenthesised series of statements), the entire block is parsed and then executed. Any %var% within the block will be replaced by that variable's value at the time the block is parsed - before the block is executed - the same thing applies to a FOR ... DO (block).

    Using !var! in place of %var% accesses the changed value of var.

提交回复
热议问题