批处理文件中的输入和变量

Input and variables in batch files

我正在制作一个批处理文件来更新我的 svn 存储库并复制它的日志,但是一旦我进入 if 语句,我得到 "goto was unexpected at this time" 并且对于我的输入变量回显它只是说"echo ECHO is on"。大部分时间我都在用这个,但不管输入是什么,它总是会说第一个 input == "y" 块是真的。

@echo on
set /p UserInput = Are you sure you want to update your repo? 

echo %UserInput% 

if %UserInput% == "y" goto Update

if %UserInput% == "n" goto :EOF


:Update

svn update

Echo Creating the basic log.
svn log > BasicLog.log
:: creates the non-verbose log

Echo Creating the verbose log.
svn log -v > verboseLog.log
::creates the verbose log

set 语句中 = 两边不能有空格。您创建了一个名为 %UserInput %.

的变量
set /p UserInput=Are you sure you want to update your repo?

对于第二部分,您必须在比较运算符的 两边使用引号,

if /i "%UserInput%"=="y" goto Update

/i 使比较不区分大小写。

逻辑:考虑如果输入既不是 y 也不是 n

会发生什么

线索:这是有效的:

if /i not "%UserInput%"=="y" goto somewhere