Batch Script - Parameter Nested Inside Variable? -
here's scenario:
i have parent script calls dozen child scripts, 1 of complex folder/file syncing operation. each of child scripts writes variable batch file (e.g. variable.bat), loaded parent script @ next execution.
the folder syncing script chooses large list of folders based upon parameter passed via parent script.
the child script's set command looks this:
echo set pair-folder-%1=yes>>c:\variable.bat
this produces variable @ next run loaded parent script. herein lies rub: how script action (via if trap) calls variable next time child script comes around? imagine if trap this:
if %pair-folder-%1%=yes goto nopair
the problem can't seem batch interpret correctly - have tried nesting variable few different ways, using delayed expansion, etc. necessary map parameter local variable first?
basically, once parent scripts calls variable.bat @ next execution, how reference newly set variable within child script?
since appending set pair-folder-%1=yes
lines variable.bat
you'll varable.bat
establish increasing set of pair-folder-*
variables.
now if want check whether pair-folder-%
set, then
if defined pair-folder-%1 ...
will you.
if want find value of pair-folder-%1 (ie it's not set or not set) then
set "valuefound=" /f "tokens=1*delims==" %%i in ( 'set pair-folder-%1 2^>nul' ) ( if /i "%%i"=="pair-folder-%1" set "valuefound=%%j" )
should - valuefound
"set" no value (ie undefined) if variable undefined else value.
Comments
Post a Comment