如果变量等于数字goto

Bri*_*ant 5 batch-file

如果一个变量等于,例如1然后gotostart1,但如果同一变量等于2然后gotostart2.

这是我到目前为止:

if %method% == "1" (goto start1)
if %method% == "2" (goto start2)

:start1
echo start1
pause
exit

:start2
echo start2
pause
exit
Run Code Online (Sandbox Code Playgroud)

但即使method变量是等于2它总是呼应我start1...

Bat*_*eba 6

你必须小心空白.写

if "%method%"=="1" (goto start1)

等等.您可能需要或不需要额外的报价%method%,具体取决于您如何设置您的环境变量.