cmd如果脚本不起作用

时间:2013-01-12 12:12:22

标签: if-statement batch-file cmd

@echo off
pause
color 0a
mode 1000

set /p apps = where do you want to go to?
echo metrix = 1
echo nothing = 2
pause

if %apps% == 1 goto metrix
if %apps% == 2 goto nothing

:metrix
:start
echo %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random% %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random% %random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%%random%
goto start

:nothing
echo nothing
pause
exit

为什么不起作用?

我从教程中复制了它,我不知道为什么它不起作用。

2 个答案:

答案 0 :(得分:1)

在以下语句中删除“=”之前和之后的空格。

设置/ p apps =你想去哪里?

答案 1 :(得分:0)

除了CuriousMind的建议,你也应该这样做比较:

if "%apps%"=="1" goto metrix
if "%apps%"=="2" goto nothing

使用引号和删除冗余空间更安全。你可能也想写

echo metrix = 1
echo nothing = 2
set /p apps = where do you want to go to?

以便在问题之前显示回声。