批处理文件在这种特殊情况下无法打印变量

问题描述 投票:2回答:1

我想在控制台中打印变量。但是,我可以看%variable_name%...

这是一个可以解释我的情况的示例代码。

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

我想要的是::

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

结果::

%a% and i respect you, answer!

我怎么解决这个问题?? (我更新了我的问题,对不起...)

windows batch-file command-line cmd
1个回答
4
投票

首先,您需要变量a内容中的百分号。加倍他们告诉解析器你想要他们的文字而不是b的(当前)内容。 然后你需要另一层扩展来评估%a%(变量)到%b%(带百分号的文字)然后评估%b%b的内容:

Set a=%%b%% and i respect you, answer!
Set b=lolol i'm happy
call Echo %a%
© www.soinside.com 2019 - 2024. All rights reserved.