Conventional and delayed expansion

Variable expansion is a parsing step during which variables get replaced in the command line.

This step in fact consist of two different step. The first, the conventional expansion and the delayed expansion. The first takes places as the file is read by pBat. The second one takes place just before the command execution.

Conventional expansion

Conventional expansion takes places at every new line read. It can not be discarded.

During this step pBat searches string delimited by some %. If pBat finds any of those, it will consider it to be variable names and replace it by their content.

Once pBat encounters such a string, it proceeds the following way :

Some options can also be specified during the expansion by inserting a column : between the % signs just after the variable name. The following options can be used :

Delayed expansion

Delayed expansion takes place just before line execution. This step can be discarded via the SETLOCAL command using the ENABLEDELAYEDEXPANSION or DISABLEDELAYEDEXPANSION options.

Delayed expansion works exactly as conventional expansion excepting that it uses ! instead of %.

It enables some very frequent batch programming issue to be solved :

Special var expansion

Special variables just before delayed expansion. This topic is discussed on the associated page.

Compatibility

Compatible with cmd.exe.

Available since 0.7

See also

Environment variables, Special variables, SETLOCAL command, Specification index