0

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?

ZeekPlayz
  • 125
  • 7
  • 1
    This management is described at [this answer](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990), although the topic is different... – Aacini Dec 07 '18 at 14:19

2 Answers2

5

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%!

SomethingDark
  • 13,229
  • 5
  • 50
  • 55
-2

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%
Shep
  • 638
  • 3
  • 15
  • I am attempting to echo %b% by echoing the value of %a% like %%a%%, where it will expand the INNER %a% to b, but keep the out percent symbols, which are then expanded to the contents of B. – ZeekPlayz Dec 07 '18 at 05:55