0

I have a series variable named Installer1 to Installer18 I am trying to install all installer 18 using a loop, so far I have this code to check if I am getting the value but the real value of variable is not reflecting, I believe there is missing on my code but I have tried my best but it is not enough. Thank you in advance

Here is what I have so far

enter image description here

I've got this result, I want to echo the value of the variable i declared on top of my loop but I got the variable name instead of value. I am not sure how to concatenate string and script will look it as a variable name.

enter image description here

I tried below code: enter image description here

And I got this result:

enter image description here

  • Please post scripts and echoes as text rather than images! – aschipfl Nov 08 '19 at 00:25
  • It is not duplicate since I did not see any items passing variables, or did I miss some thoughts. – Brandon Jake Sullano Nov 08 '19 at 02:41
  • Well, in my opinion it is a duplicate (particularly see [this thorough answer](https://stackoverflow.com/a/10167990)) since you have got "nested variables" or "pseudo-arrays" (or however one may call such a concept). Anyway, try this: `for /L %%x in (1,1,18) do call echo/%%Installer%%x%%`... – aschipfl Nov 08 '19 at 10:43
  • Here's a simple example line to completely replace your [tag:for-loop]: `For /F "Tokens=1*Delims==" %%# In ('Set Installer 2^>NUL') Do Echo="%__AppDir__%msiexec.exe" /i "%%$" /qn`. In this example, I've combined both an `echo` and installer `command`, for you to see how the output looks, _(subject to the cmd.exe window being open long enough for you to read it)_. You would obviously adjust that part to be either one or both as necessary. – Compo Nov 08 '19 at 14:00

1 Answers1

0

Use array , Please try this.

@echo off
setlocal enabledelayedexpansion
SET var[0]=A
SET var[1]=foo bar
SET var[2]=123
for %%a in (0,1,2) do (
    echo !var[%%a]!
)
echo Get one of the variables directly: %var[1]%
Siva Karuppiah
  • 995
  • 1
  • 8
  • 17