Evaluate Variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ccbdos
Posts: 2
Joined: 13 Mar 2012 13:46

Evaluate Variable

#1 Post by ccbdos » 13 Mar 2012 14:09

I am sure there is a very simple answer to this, but I have searched and can't find it.

I would like to evaluate a variable using a variable as the variable's name. Clear as mud?

A simple example:

set variable1=hello
set variablename=variable1
echo %%%variablename%%%

The desired result is:

hello

The %%%'s are obviously not correct, but I'm looking to replace the third line with the "magic" that will produce the desired result.

Thanks in advance for any help... and more importantly for fogiving my ignorance and lack of ability to find a solution... it's got to be simple and somewhere on dostips... I just can't figure it out, or find it.

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Evaluate Variable

#2 Post by aGerman » 13 Mar 2012 15:36

Use either ...

Code: Select all

call echo %%%variablename%%%

... or ...

Code: Select all

setlocal EnableDelayedExpansion
echo !%variablename%!

Regards
aGerman

ccbdos
Posts: 2
Joined: 13 Mar 2012 13:46

Re: Evaluate Variable

#3 Post by ccbdos » 13 Mar 2012 16:12

Thank You!

I missed the call on the first and had actually tried the second... without setting EnableDelayedExpansion. Thanks for forgiving my ignorance and helping me out! I much appreciate it!

Post Reply