If statement 超级简单错误,批处理if语句

If statement 超级简单错误,批处理if语句,if-statement,batch-file,If Statement,Batch File,我的短批处理文件一直失败。我的if有什么问题 :user set /p usercommand = "Input: " if %usercommand% equ "done" echo got here! goto end else echo not done goto user 首先-使用set/p usercommand=设置名为usercommand的变量。删除预期名称后的空格(因此它变为set/p usercommand=) 这就是说,这将使您遇到另一个错误,因为if-else语法

我的短批处理文件一直失败。我的if有什么问题

:user
set /p usercommand = "Input: "

if %usercommand% equ "done"
echo got here!
goto end

else
echo not done
goto user

首先-使用
set/p usercommand=
设置名为
usercommand
的变量。删除预期名称后的空格(因此它变为
set/p usercommand=

这就是说,这将使您遇到另一个错误,因为if-else语法不正确。它必须是:

if "%usercommand%" equ "done" (
 your commands here
) else (
 your commands here 
)
请注意,我引用了
%usercommand%
。否则,您的比较将永远不会是真实的(当然,除非您要求明确引用您的输入)