Printing value of multiple variable expression in Windows Batch Files -
so i'm trying print out value of variable in form of (variable.variable). can't figure out how it. closest thing got was:
echo %"%dog.index%"%
which printed out:
dog.index
and tried add set of % tags , printed out:
%""%
any great! thanks.
(edited)
i'm trying make array-like variable. want value of dog.1, dog.2, dog.3 printed out , assign them such:
set dog.%index%=(value)
and %index% counter increment. trying "%dog.index%" not work, neither %dog%.%index% again.
you'll have use delayed expansion of environment variables. command setlocal enabledelayedexpansion
initialises mode, after can use delayed expansion enclosing variables in !
instead of %
.
here's illustration of how can used:
@echo off setlocal enabledelayedexpansion echo initialising... /l %%i in (1,1,5) set dog.%%i=!random! echo displaying... /l %%i in (1,1,5) echo %%i: !dog.%%i! set index=3 echo dog.%index% !dog.%index%!
output:
initialising... displaying... 1: 1443 2: 6940 3: 24198 4: 8054 5: 14092 dog.3 24198
you can see last part of script employs both immediate , delayed expansion. immediate expansion replaces %index%
3
, results in variable name of dog.3
. delayed expansion replaces !dog.3!
expression value of dog.3
variable.
Comments
Post a Comment