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

1
  • You may read a full description on array management in batch files at this post Commented Jul 27, 2015 at 21:04

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.