我想知道一切是否正常,因为我的值“ H1”不适用于此集中
set /p LL1=
IF "%LL1%" == "1" (
goto :LL1
) ELSE (
IF "%LL1%" == "EN" (
goto :LL1
) ELSE (
goto :LLERR
IF "%LL1%" == "H1" (
goto :LLH
) ELSE (
IF "%LL1%" == " " (
goto :LLERR
) ELSE (
IF "%LL1%" == "" (
goto :LLERR
) ELSE (
goto :LLERR
)
)
)
)
)
1 / EN输入有效,H1无效,空格/空白被按预期阻止,我真的迷失了这个,知道吗?
谢谢。
答案 0 :(得分:2)
这是“标准”方式:
set /p LL1=
IF "%LL1%" == "1" goto :LL1
IF "%LL1%" == "EN" goto :LL1
IF "%LL1%" == "H1" goto :LLH
goto :LLERR
但是,我会这样:
set /p LL1=
rem Call the given label, hide error message
call :Label-%LL1% 2> NUL
if errorlevel 1 goto :LLERR
echo Subroutine called OK
goto :EOF
:Label-1
:Label-EN
echo This is LL1
exit /B
:Label-H1
echo This is LLH
exit /B
或者更好的是,使用choice
来代替set /p
答案 1 :(得分:-2)
set /p LL1=
IF "%LL1%" == "1" (
goto :LL1
IF "%LL1%" == "EN" (
goto :LL1
IF "%LL1%" == "H1" (
goto :LLH
IF "%LL1%" == " " (
goto :LLERR
IF "%LL1%" == "" (
goto :LLERR
) ELSE (
goto :LLERR
)
)
)
)
)
这样更好吗?