0

I'm looking for a way to exchange variable values (strings) in a batch-file while looping over a command.

varA has 4 different values and varB 18 different values

@echo off
set varA="foo"
set varB="bar"

echo %varA% and %varB%  (sample command)
pause

the goal is to loop the command 72-times (=4*18) with the different variable values. I can produce a list with all the combinations ready to use e.g.

varA="foo"
varB="bar"

varA="foo2"
varB="bar"
...

I'm guessing this is achievable in batch with a external config- or text-file, but I seem to be searching for the wrong things. Could someone point me in the right direction?

2
  • 1
    FOR %%a IN ("a" "b" ...) Commented Jun 11, 2018 at 13:47
  • I really zoned out there. You're absolutely right. Commented Jun 11, 2018 at 14:13

1 Answer 1

1

You should be able to nest a For loop inside another.

Example:

@Echo Off
Set "varA=1 2 3 4"
Set "varB=1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18"
For %%A In (%varA%) Do For %%B In (%varB%) Do Echo %%A %%B (sample command)
Pause
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.