我有以下批处理文件的代码(?):BAT文件:奇怪SET行为
@echo off
SET INSTALL_PATH=c:\program files\
:ask_again
if exist "%INSTALL_PATH%" (
SET /P PATH_EXISTS_ANSWER=Path exists, overwrite?[y/n/default:n]
if not defined PATH_EXISTS_ANSWER (
echo You chose default action^(N^). Try another installation path.
echo.
goto default
)
if /I "%PATH_EXISTS_ANSWER%"=="n" (
echo You chose not to use existing folder. Try another installation path.
echo.
goto noc
)
if /I "%PATH_EXISTS_ANSWER%"=="y" (
echo You chose to overwrite existing folder. Existing files will be overwritten.
echo.
goto yesc
)
echo Please choose Y or N
echo.
goto ask_again
)
:yesc
echo you said yes
goto end
:default
echo you said default
goto end
:noc
echo you said no
goto end
:end
而且它的确定,当我只选择按Enter键默认操作。但是当我使用N或Y键时,PATH_EXISTS_ANSWER的值似乎是未定义的,脚本进入另一个循环,然后,无论我回答什么,脚本somewhy使用以前的答案。 例如,如果我回答Y脚本再次询问,如果我选择N它键入“你说是”。 我在做什么错?
我怀疑CMD.exe在光标离开IF块时计算变量的实际值。但为什么? – 2012-01-12 11:55:54