我在扩展数组变量时遇到问题。这是我正在尝试做的事情:
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
我尝试过使用延迟扩展,但这也无济于事
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
我尝试了许多变化,包括
!array[%%x]!
!%array[%%x]%!
!%array[!%x%!]%!
可以帮忙吗?
答案 0 :(得分:2)
看来您已经把这件事弄乱了。正确的是:
@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