I would suggest you try and avoid using shift completely if you might need the parameters later in your script.
2 ideas for you:
1) Specific to the code you have shown, you could use a for loop:
Code: Select all
@ECHO OFF
echo start: %1
for %%a in (%*) do echo %%a
echo end: %1
2) You can use a for loop to go through all the parameters, and assign them all to variables. These variables would then be used in the rest of your code:
Code: Select all
@ECHO OFF
setlocal enabledelayedexpansion
set idx=0
for %%a in (%*) do (
set /a idx+=1
set param!idx!=%%a
)
echo There were %idx% parameters passed.
echo Start: %param1%
for /l %%a in (2,1,%idx%) do echo.!param%%a!
echo End: %param1%
so param1 = %1, param2 = %2, param3 = %3 etc.
or the same using shift to assign variables and the "call" trick to avoid delayedexpansion:
Code: Select all
@echo off
set idx=0
echo Start: %1
:loop
set /a idx+=1
set param%idx%=%1
shift
if not "%1"=="" goto :loop
for /l %%a in (2,1,%idx%) do call echo.%%param%%a%%
echo End: %param1%