JustTemp
JustTemp

Reputation: 75

Batch file Variable cannot be printed in this special situation

I want to print variable in the console. But, I can watch %variable_name%...

This is an example code which can explain my situation.

Set a=%b% and i respect you, answer!
Set b=lolol i'm happy
Echo %a%

What I want::

lolol i'm happy and i respect you, answer!

Results::

%a% and i respect you, answer!

How can i solve this problem?? (I updated my question, sorry...)

Upvotes: 3

Views: 106

Answers (1)

Stephan
Stephan

Reputation: 56180

First, you need the percent signs in the content of the variable a. Double them to tell the parser that you want them literal instead of the (current) content of b.
Then you need another layer of expansion to evaluate %a% (variable) to %b% (literal with the percent signs) then to evaluate that %b% to the content of b:

Set a=%%b%% and i respect you, answer!
Set b=lolol i'm happy
call Echo %a%

Upvotes: 4

Related Questions