• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

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

Felecha

Golden Member
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
😀oneSetArgs

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?
 
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.
 
Back
Top