0

I am trying to write "bootstrapper" script which parses and passes arguments into further applications in my framework. The minimal, reproducable example below, actual application is much more complicated

The basic syntax for that script is

bootstrapper.bat type command "foo=1" "bar=test2" "baz=true"

and it should call

type/command.bat 1 test2 true

The problematic fragment is this nested for-loop:

setlocal enabledelayedexpansion

rem this is actually fetched elsewhere in live app
set procedure_arguments_count=3

set arguments=
for /L %%L in (1,1,!procedure_arguments_count!) do (
    for /f "tokens=1,2 delims==" %%a in ("%~3") do set arguments=!arguments! %%b
    shift /3
)

echo !arguments!

The problem is arguments are equals to 1 1 1 instead of 1 test2 true after executing this loop.

I believe the inner loop is pre-populated with %~3 being set as foo=1 and ignoring the shift command. I cannot change shift as I need to support 9+ arguments, nor can I remove outer loop (for other reasons).

The question is - can I have delayed expansion for script arguments?

4

2 に答える 2