在 if 块内设置环境变量 BOOBOO 的值似乎不会设置它。但是,它是在 if 块结束后设置的。为什么它在 if 块中没有值?
在 Microsoft Windows XP [版本 5.1.2600] SP3 上运行
echo BOOBOO is +++%BOOBOO%+++
echo step 1
setlocal enableextensions
IF "%BOOBOO%" == "" (
echo step 2
SET BOOBOO=xyz
echo step 3
echo BOOBOO has been set to %BOOBOO%
echo BOOBOO part is %BOOBOO:~0,2%
echo step 4
)
echo step 8
echo BOOBOO ends up as %BOOBOO%
echo step 9
EXIT /B 0
===
M:> t
BOOBOO is ++++++
step 1
step 2
step 3
BOOBOO has been set to
BOOBOO part is ~0,2
step 4
step 8
BOOBOO ends up as xyz
step 9