-1

I have an issue with expanding array variables. Here is what I am trying to do:

set array[0]=a
set array[1]=b
set array[2]=c

 FOR /l %%x IN (0 1 2) do curl  -XGET  -H "Authorization: Bearer %TOKEN%" "https://baseURL/%array[%%x]%/params" -H "content-type: application/json" > %%x.json

I have tried using delayedexpansion, but it didn't help either

setlocal enabledelayedexpansion
FOR /l %%x IN (0 1 2) do curl  -XGET  -H "Authorization: Bearer %TOKEN%" "https://baseURL/!array[%%x]!/params" -H "content-type: application/json" > %%x.json

I've tried many variations including

!array[%%x]!
!%array[%%x]%!
!%array[!%x%!]%!

Can you please help?

bekon
  • 305
  • 1
  • 4
  • 12
  • 3
    Of course that `!array[%%x]!` should work! All this management is explained at [this answer](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990)... – Aacini Jan 08 '19 at 18:43
  • Possible duplicate of [Arrays, linked lists and other data structures in cmd.exe (batch) script](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script) – double-beep Jan 09 '19 at 08:31

1 Answers1

2

It seems you have messed up this in your side. The correct would be:

@echo off
setlocal EnableDelayedExpansion

set array[0]=a
set array[1]=b
set array[2]=c

for /L %%A IN (0 1 2) do curl  -XGET  -H "Authorization: Bearer %TOKEN%" "https://baseURL/!array[%%A]!/params" -H "content-type: application/json" > %%A.json
double-beep
  • 5,031
  • 17
  • 33
  • 41