6

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!

3 Answers 3

11
for %%i in %LIST% do CALL echo %%i=%%%%i%%

should solve your problem.

Sign up to request clarification or add additional context in comments.

Comments

3

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!

Comments

1

It wasn't very clear what you wanted to do. Try and see if this solves your problem:

@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

:: deletes the parentheses from LIST
set _list=%LIST:~1,-1%
for  %%G in (%_list%) do (
    set  _name=%%G
    set  _value=!%%G!
    echo !_name! = !_value!
)

the script prints the name and the corresponding value of all the environment variables whose names are listed in the variable LIST.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.