0

i want set varable instead index of array in loop (batch script) like:

@ECHO OFF

set array[1]=22750289 512
set array[2]=22750289 5600
set array[3]=22750289 5612

for %%N in (1,1,3) do (
    echo %array[%%i]%
    echo %array[1]%
 )

but result : ECHO is off. 22750289 512 ECHO is off. 22750289 512 ECHO is off. 22750289 512

POLNET
  • 23
  • 4
  • You may read a full description on array management in batch files at [this post](http://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990) – Aacini Jul 27 '15 at 21:04

1 Answers1

3

For this you need to enable delayed variable expansion using setlocal:

@echo off

setlocal EnableDelayedExpansion

set array[1]=22750289 512
set array[2]=22750289 5600
set array[3]=22750289 5612

for /L %%N in (1,1,3) do (
echo !array[%%N]!)

endlocal

Notice that the variables are no longer available after endlocal.

For more information about delayed variable expansion reference this thread.

Community
  • 1
  • 1
aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • 1
    Also worth nothing that you're going to want to use a `for /L` loop instead of the regular `for` loop you've got there. – SomethingDark Jul 27 '15 at 20:21