Batch file 使用if-else在变量中批处理文件空间

Batch file 使用if-else在变量中批处理文件空间,batch-file,Batch File,我这里有这个代码: :a set /p unit=Unitpile Entry: echo %unit% >> unitpile.txt if %unit% EQU exitscript ( goto b ) else ( goto a ) 每当%unit%中有一个空格,所以只有两个字,文件就会关闭。 请帮忙。。。还是与语法有关。 顺便说一句,我有所有其他合适的标签,只是这是整个代码的一个片段。这是您的批处理代码和一些注释。您可以在这里看到如何正确使用双引号 :a rem De

我这里有这个代码:

:a
set /p unit=Unitpile Entry:
echo %unit% >> unitpile.txt
if %unit% EQU exitscript (
goto b  
) else (
goto a
)
每当%unit%中有一个空格,所以只有两个字,文件就会关闭。 请帮忙。。。还是与语法有关。
顺便说一句,我有所有其他合适的标签,只是这是整个代码的一个片段。

这是您的批处理代码和一些注释。您可以在这里看到如何正确使用双引号

:a
rem Define environment variable unit with a double quote as default value.
set "unit=""
set /p "unit=Unitpile Entry: "
rem Remove all double quotes entered by user. If the user has not entered
rem anything, the default double quote is removed. The default is necessary
rem in case of user enters nothing to make the next line working also in
rem this special case.
set "unit=%unit:"=%"
rem Has the user entered anything at all?
if "%unit%"=="" goto :EOF
echo %unit%>>unitpile.txt
if /I "%unit%"=="exitscript" (
    goto b
) else (
    goto a
)
:b