Articles

DOS variables

December 6, 2005 at 05:22:09
Specs: XP, P4 2.80Hz

Hi there,

Is it possible to work with arrays in DOS?
Otherwise I have the following code:
-----
set var1=hello
set var2=you
set var3=...
set max=3
FOR /L %%i IN (1,1,%max%) DO echo %var%%i% ??
----
I'd like to use the loop to walk through the variable's values, not the literal variables.
So "hello" instead of "var1"... and so on.
Anyway, %var%%i% is not possible!
Anyone?

TIA!


See More: DOS variables

Report •


#1
December 6, 2005 at 06:08:50

Try this:

::=========
@echo off

set var1=hello
set var2=you
set var3=...
set max=3
FOR %%i IN (%var1% %var2% %var3% %max%) DO echo %%i
::=====


If at first you don't succeed, you're about average.

M2


Report •

#2
December 6, 2005 at 07:11:54

You need to enable the "delayed expansion", then using the ! marker to declare the delayed variables you can access array type variables as following:

@Echo Off
SetLocal EnableDelayedExpansion

Set var1=hello
Set var2=you
Set var3=...
set max=3
For /L %%i in (1,1,%max%) Do Echo !var%%i!

EndLocal


Report •

#3
December 6, 2005 at 13:00:09

wow! thanx a lot

Report •

Related Solutions


Ask Question