0

I have script like this:

set list=%list%;AAA
set list=%list%;BBB
set list=%list%;CCC

set /a i=-1
for %%a in (%list%) do (
    set /a i=i+1

   ::print ok
   echo %%a 

   ::print error
   echo %%list[!i!]%% 
)
pause

How can I fix the print error when using index to query array?

oguz ismail
  • 1
  • 16
  • 47
  • 69
DaveG
  • 491
  • 1
  • 6
  • 19
  • 1
    Windows batch files don't have arrays. – CherryDT Jul 11 '20 at 16:02
  • You never defined the variables `list[0]`, `list[1]` etc. (as CherryDT mentioned, there is no such thing as an array, just independent variables. But you can [emulate arrays](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script) with independent variables. Even good enough that some people insist to call it an array) – Stephan Jul 11 '20 at 18:35
  • [**Never** use `:label` nor `:: label-like comment` inside a command block enclosed in `()` parentheses](https://stackoverflow.com/a/32147995/3439404). – JosefZ Jul 11 '20 at 20:03

0 Answers0