I have an array defined as LIST=(a b c d e)
. The a, b, c, d, e
are set as system variables, eg. a=AAA, b=BBB
, etc.
In a batch script, I would like to do a for loop looking like:
for %%i in %LIST% do echo %%i=%%%i% (unfortunately, this doesn't work)
What I want to achieve is that %%i (a) = %%%i% (%a%)
, which will be resolved as system variable, thus instead of showing %a%
, it'll be resolved as a=AAA
.
Do you have any idea how to do it in a batch script?
Thanks!
for %%i in %LIST% do CALL echo %%i=%%%%i%%
should solve your problem.
This is the same answer of Lorenzo Donati, but in a slightly simpler way...
@echo off
setlocal enabledelayedexpansion
set LIST=(a b c d e)
set a=value of A
set b=value of B
set c=value of C
set d=value of D
set e=value of E
for %%G in %LIST% do echo %%G = !%%G!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With