Is this the meaning of "%1" in a script?

Felecha

Golden Member
Sep 24, 2000
1,434
0
0
I'm trying to figure out a script used to start the Tomcat webserver, startup.bat. There's a set of lines that I believe I understand, but I'm curious to make sure

set CMD_LINE_ARGS=
:setArgs
if ""%1""=="""" goto doneSetArgs
set CMD_LINE_ARGS=%CMD_LINE_ARGS% %1
shift
goto setArgs
:DoneSetArgs

etc etc

It looks like an ordinary while loop -- until the value %1 is empty, add the value of %1 to the list of arguments. The thing I want to know is -- is it somehow a default of some kind that "%1" will represent one of a list of command line arguments? In this case I don't see %1 set to anything in any part of the script. I see variables set with SET all the time, but nowhere is %1 set to anything, or declared, or even mentioned, before it reaches the code lines above. So I'm presuming it's supposed to hold a value passed to the startup.bat itself in the call to startup.bat. But for that it would have to be part of the scripting languiage itself?
 

Moonbender

Golden Member
Oct 19, 2000
1,046
0
0
You've got that right. In Windows Batch files, %1 represents the first argument passed to the file. In the loop, %1 is added to CMD_LINE_ARGS. After that SHIFT is called, which sets %1 to contain the second parameter instead, and so on until there are no more parameters. See also help shift.