Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有%SystemRoot%\blahblahblah一个变量(例如,variable a)。但echo !a!会返回%SystemRoot%\blahblahblah(不展开%SystemRoot%)。我该如何扩展它?
%SystemRoot%\blahblahblah
variable a
echo !a!
%SystemRoot%
您可以使用调用子程序的技巧,这将导致变量被扩展两次:
@Echo Off set a=%%SystemRoot%%\blahblahblah call :reparse set b=%a% echo value of a: %a% echo value of b: %b% goto :EOF :reparse %* goto :EOF
该:reparse子例程只执行其所有参数。第一次扩展发生在执行调用时,第二次发生在 %* 被解释为set b=%SystemRoot%\blahblahblah.
:reparse
set b=%SystemRoot%\blahblahblah