This question is similar to that of Echo batch file arrays using a variable for the index? but it doesn't answer my question.
I have a batch file that contains a list. I am iterating through a for loop and want to print out an element from the list with each iteration using the iteration number (i.e. list[i]
)
I am using SETLOCAL enableextensions enabledelayedexpansion
and I've tried using:
!list[%i%]!
%list[%i%]%
!list[!i!]!
I'm aware I could use FOR /L
but this would not work in the context I want to use this.
Here's the code I'm currently using
SETLOCAL enableextensions enabledelayedexpansion
SET list[0]=1
SET list[1]=2
SET list[2]=3
SET list[3]=4
SET list[4]=5
SET /a i=0
FOR /L %%G IN (1,1,5) DO (
echo list[!i!] = %list[!i!]%
SET /a i+=1
)
Expected:
list[0] = 1
list[1] = 2
list[2] = 3
list[3] = 4
list[4] = 5
Actual:
list[0] =
list[1] =
list[2] =
list[3] =
list[4] =