ZeekPlayz
ZeekPlayz

Reputation: 125

Set a variable to the contents of another variable

I am attempting to create a program that will essentially "Emulate" variables.

I tried testing this issue with this code:

@echo off
set a=b
set b=c
:: The program should echo %b% because it is expanded with double percentages
echo %%a%%

the Program only echoes "%%a%%", instead of expanding to %b%, which should result in the program echoing C.

What am I doing wrong?

Upvotes: 0

Views: 89

Answers (2)

SomethingDark
SomethingDark

Reputation: 14304

You can use call and use a doubled set of percent signs to get a value of c.

call echo %%%a%%%

Alternatively, you can put setlocal enabledelayedexpansion at the top of the script and use echo !%a%!

Upvotes: 5

Shep
Shep

Reputation: 628

From the answer at Batch character escaping

It appears the formal definition is quite vague:

May not always be required [to be escaped] in doublequoted strings, just try

Therefore, try unescaped:

 echo %a%

Upvotes: -2

Related Questions