I have this code:
@echo off
setlocal EnableDelayedExpansion
rem FILL ARRAY
set n=0
for %%a in (A B C) do (
set fname[!n!]=%%a
set /A n+=1
)
rem FIRST OUTPUT
for /L %%i in (0,1,2) do (
echo !fname[%%i]!
)
echo/
rem SECOND OUTPUT
echo !fname[0]!
echo !fname[1]!
echo !fname[2]!
echo/
rem THIRD OUTPUT DOESN'T WORK
set n=0
for %%a in (A B C) do (
echo !fname[!n!]!
set /A n+=1
)
And get:
A
B
C
A
B
C
n
n
n
For some reasons I need output in third style and expect the same output like in first and second case but I can't understand what's wrong with it.
Update. Thank you, folks. I guess I've confused you a little but really I need to use this output in variable, so I've found this working solution, maybe it'll help somebody else:
rem THIRD OUTPUT WORKS
set n=0
for %%a in (A B C) do (
for /f "tokens=2* delims==" %%x in ('set fname[!n!]') do (
<... using %%x...>
)
set /A n+=1
)
rem %%x contains output now and can be used anywhere