@ECHO OFF
SETLOCAL
call :test one two three
call :test four five
call :test seven eight nine ten
CALL :test
goto :eof
:test
rem for /f "delims==" %%a in ('set parm 2^>nul') do set "%%a="
set /a parmcnt=0
:testlp
set /a parmcnt+=1
SET "parm%parmcnt%=%1"
SHIFT
IF DEFINED parm%parmcnt% GOTO testlp
SET /a parmcnt-=1
ECHO %parmcnt% parameters
IF %parmcnt% gtr 0 FOR /L %%a IN (1,1,%parmcnt%) DO CALL ECHO %%parm%%a%%
ECHO -------------------
SET parm
ECHO ===================
GOTO :EOF
The meat here is the :testlp loop. The parameter count parmcnt is incremented, and the variable parm... is set to %1 - the first parameter, then the paramter list is SHIFTed which simply removes the first parameter from the apparent list.
if the parm... has a value, then try again, until all of the parameters have been assigned to parm*
decrement the parameter count (since the last assignment attempt assigned a value of nothing as %1 did not exist) and display the results.
The result-display is in two parts. The first uses a parsing trick (to avoid delayed expansion which is a whole new ball-game). The parser first substitutes for the metavariable %%a, so what is executed is call echo %%parm1%% etc. for 1 to %parmcnt%. calling the echo executes echo %parm1% in a subshell.
The second simply shows all variables set which start parm. Note that parm%parmcnt+1% will always be empty, but there may be stray parms set from prior invocations of :test
Hence the remmed-out for ... set parm line which clears all variables starting parm. Removing the rem from this line would dispose of the stray variables problem, but note that it would also clear any variablename that starts parm - like parmlimit had parmlimit been set.
:testsubroutine isfor %%a in (%*) do echo %%a(where%*is a list of "all parameters")exit /Bafter thecallcommand line to not continue execution unintentionally...