Lets have the following example.bat
and call it with arguments 1
,2
and 3
:
@echo off
(
shift
shift
echo %1
)
As the variable expansion will change after the the end brackets context is reached the output will be:
1
As this might be an issue when shifting inside brackets to access the argument you'll need to use call:
@echo off
(
shift
shift
call echo %%1
)
now the output will be 3
. As CALL
command is used (which will lead to additional variable expansion) with this technique the arguments accessing can be also parametrized:
@echo off
set argument=1
shift
shift
call echo %%%argument%
with delayed expansion:
@echo off
setlocal enableDelayedExpansion
set argument=1
shift
shift
call echo %%!argument!
the output will be
3