In tip 6792 » How many parameters can I pass to batch file, we learned
that their is no limit to the number of parameters you can pass to a batch file,
but the highest parameter that you can
address is %9.
I have scripted LastNNP.bat to return the content of the last non-null parameter of any call.
The syntax for using LastNNP.bat is:
call lastnnp lastval \[p1 p2 p3 .... pn\]
where:
lastval is a call directed environment variable that will contain the contents (string) of the last parameter, and p1, P2, P3, and pn are the parameters.
Examples:
If your batch file was called, as in:call YourBatchFile AAA BBB CCC DDD EEE FFF GGG HHH III JJJ KKK LLL MMM
then
call lastnnp lastval %*
If you use a FOR command to parse for an unknown number of parameters, and you are only interested in the last parameter, as in:
for /f "Tokens=2-27" %%a in ('rsm view /tlibrary /guiddisplay^|Findstr /i /c:"Ultrium"') do (
call lastnnp lastval %%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z
)
LastNNP.bat contains:
@echo off if \{%1\}\{\} @echo Syntax: call lastnnp lastval \[p1 p2 p3 .... pn\]&exit /b 1 setlocal set valname=%1 shift :loop if \{%1\}
\{\} goto found set last=%1 shift goto :loop :found endlocal&set %valname%=%last% exit /b 0