启用S​​ETLOCAL时如何在IF子句中回显环境变量

时间:2019-05-22 20:43:20

标签: windows batch-file

如何“回显”应该扩展环境变量本身的(环境)变量的值?

示例BAT:

echo OFF
SETLOCAL

echo running test ...

set /a "YesPleaseContinue=0"
IF defined windir (
   set /a "YesPleaseContinue=1"
)

IF %YesPleaseContinue% GEQ 1 (
   set MyCustomVar=%WinDir%\System32\regsvr32.exe
   echo DEBUG1: %MyCustomVar%
) ELSE (
   echo condition not met
)

echo DEBUG2: %MyCustomVar%

timeout 120

这将产生以下输出:

running test ...
DEBUG1:
DEBUG2: C:\WINDOWS\System32\regsvr32.exe

为什么“ echo”在带有“ DEBUG1”的行中输出 empty 内容?

0 个答案:

没有答案