How to use %0, %1, %2, etc. and the SHIFT command
Posted: 27 Nov 2011 14:23
How do I use and set replaceable parameters such as %1 in batch?
How does the SHIFT command work with these?
How does the SHIFT command work with these?
A Forum all about DOS Batch
https://www.dostips.com/forum/
Code: Select all
@echo off
call :func "par am1" par am2
pause
for /? |more
exit /b 0
:func
::(
echo.%*
echo.1=%1_, 1=%~1, 2=%2_
shift
echo.1=%1_, 1=%~1, 2=%2_
::)
exit /b 0
Code: Select all
myscript.bat arg1 "arg 2"
Code: Select all
call anotherscript.bat arg1 "arg 2"
call :subroutine arg1 "arg 2"
Code: Select all
myscript.bat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Code: Select all
echo %0
echo %1 %2 %3 %4 %5 %6 %7 %8 %9
:: Outputs:
:: (Full Path)\myscript.bat
:: 1 2 3 4 5 6 7 8 9
shift
echo %0
echo %1 %2 %3 %4 %5 %6 %7 %8 %9
:: Now output is:
:: 1
:: 2 3 4 5 6 7 8 9 10
Code: Select all
echo %0
echo %1 %2 %3 %4 %5 %6 %7 %8 %9
:: Outputs:
:: (Full Path)\myscript.bat
:: 1 2 3 4 5 6 7 8 9
shift /1
echo %0
echo %1 %2 %3 %4 %5 %6 %7 %8 %9
:: Now output is:
:: (Full Path)\myscript.bat
:: 2 3 4 5 6 7 8 9 10
shift /5
echo %0
echo %1 %2 %3 %4 %5 %6 %7 %8 %9
:: Now output is:
:: (Full Path)\myscript.bat
:: 2 3 4 6 7 8 9 10 11