我的代码是以下内容,当它到达第一个&#34时崩溃;如果"声明,我是新手,无法找到解决方法。没有变量,过去的if语句工作正常。究竟是什么导致了崩溃?我以前经历过这种情况,"如果"除非有一个" goto"它下面的线。是"回声"这可能导致崩溃?
:readytopack
cls
echo ========= ASSETS PACKER =========
echo Confirm the following Settings?
echo.
echo The folder to be packed is:
echo %filelocation%
echo %cd%\%filelocation%
echo Will be built to .pak in:
echo %location%
pause>nul
if "%customname%"=="0" (
echo %cd%\%location%
)
echo %cd%\%location%\%customname%
)
echo.
echo [yes] [no] (Lowercase)
echo Selecting "no" will revert a Step.
echo =================================
echo.
Set /p CMD=
if "%CMD%"=="" (
goto start
)
if "%CMD%"=="yes" (
goto pack
)
if "%CMD%"=="no" (
goto unpackerlocation
)
echo Please enter "yes" or "no" in Lowercase.
goto readytounpack
)
答案 0 :(得分:1)
您似乎有不平衡的括号,或者错过了部分脚本并在代码块中创建了标签。
如果在编写代码时缩进代码,您会发现更容易发现不平衡的括号。
这里从底部向上缩进:
:readytopack
cls
echo ========= ASSETS PACKER =========
echo Confirm the following Settings?
echo.
echo The folder to be packed is:
echo %filelocation%
echo %cd%\%filelocation%
echo Will be built to .pak in:
echo %location%
pause>nul
if "%customname%"=="0" (
echo %cd%\%location%
)
echo %cd%\%location%\%customname%
)
echo.
echo [yes] [no] (Lowercase)
echo Selecting "no" will revert a Step.
echo =================================
echo.
Set /p CMD=
if "%CMD%"=="" (
goto start
)
if "%CMD%"=="yes" (
goto pack
)
if "%CMD%"=="no" (
goto unpackerlocation
)
echo Please enter "yes" or "no" in Lowercase.
goto readytounpack
)
行16
和34
看起来是否正确?如果你删除这两行会怎么样?
修改
在上述情况下,您实际上可以删除所有这些括号:
:readytopack
ClS
Echo ========= ASSETS PACKER =========
Echo Confirm the following Settings?
Echo=
Echo The folder to be packed is:
Echo=%filelocation%
Echo %cd%\%filelocation%
Echo Will be built to .pak in:
Echo=%location%
Pause>Nul
If "%customname%"=="0" Echo %cd%\%location%
Echo %cd%\%location%\%customname%
Echo=
Echo [yes] [no]
Echo Selecting "no" will revert a Step.
Echo =================================
Echo=
Set /P "CMD= "
If "%CMD%"=="" GoTo start
If /I "%CMD%"=="yes" GoTo pack
If /I "%CMD%"=="no" GoTo unpackerlocation
Echo Please enter "yes" or "no".
GoTo readytounpack
我还建议您查看Choice
命令,当您希望将已知字符串或字符作为输入时,它比Set /P
更强大。 < / p>