Special variables

Special variables are internal variables provided by pBat. Special variables are local, thus they can not be inherited by external programs.

Special variable use

Special variables can not be modified, the can only be defined by pBat, the CALL command or the FOR command.

There is basically two types of special variables:

Those two types of variables have a slightly different expansion precedence. Argument variables are expanded simultaneously with conventionnal expansion while FOR-generated variables are expanded before the delayed expansion and the tokenization of the command line.

Argument variables %0 through %9 are set to arguments passed to the script using the command line. As a convention, %0 is always the script name when the script starts. However, when using CALL to execute a label, %0 contain the name of that label.

The %* variable contains a line containing the parameters that have been passed to the script, that is it is the content of %1 trough %9 inside a single variable plus all the parameters beyond the ninth if any has been passed. The parameters beyond the ninth one (%9) can also be retrieved using the %+ variable. On UNIX-based operating systems, it is not possible to retrieve the exact syntax of the command line. Thus %* is created using the parameters and some added quotation if necessary.

Special variable expansion

Special variables names are made of a single letter or a digit. Any ASCII character except the 33 first (ie. from 0x20) can be used. However, for readability purposes it is better to use only letters.

Special variable expansion is performed between command argument detection and delayed expansion, allowing them to affect expansion of variables.

Special variable names need to be preceded by two %, (except for %0 up to %9, %* and %+) to be developed. Some option can be enabled by using the ~ sign. These options are the following:

Several options may be combined simultaneously (up to 16 different options).

As options are letters, conflicts can happen between variables names and options. If it is the case pBat will use the longest combination of options (maximum greediness). As an example, the following code :

ECHO %%~aI

Can be interpreted in two different ways:

When the %0 variable gets expanded, pBat has a slightly different behaviour:

Note

Special variable names and options are case sensitive.

See also

Environment variables, Variable expansion, Specification index