How to do nesting in variables in batch

April 12, 2011 at 23:06:12
Specs: Windows XP
I am trying the following code to print 34 and 86. But only 34 is coming in the output. please help.
Also !myvar_!num!! is not working. Please suggest.
Thanks

@echo off
setlocal enableextensions
Setlocal EnableDelayedExpansion

set myvar_1=34
set myvar_2=86

set l=1
set num=1
for /f "tokens=* delims= " %%a in (ip.txt) do (
set /a l+=1
echo !myvar_%num%!
if !l! equ !myvar_%num%! (
set /a num+=1
echo new num is !num!
)
)

endlocal


See More: How to do nesting in variables in batch

Report •


#1
April 13, 2011 at 00:58:55
I have solved the problem with the following code !
Please suggest some other solution where nesting of variable can be done??

set myvar_1=34
set myvar_2=86

set l=1
set num=1
for /f "tokens=* delims= " %%a in (ip.txt) do (
set /a l+=1
set /a lin = myvar_!num!
set lin = !%lin%!
if !l! equ !lin! (
set /a num+=1
echo !lin!
echo new num is !num!
set /a level=!num! - 1
)
)


Report •
Related Solutions


Ask Question