我编写了一个简单的batch file来根据数字select运行常用网站。 这是我的代码。 我试图设置它,所以如果有人input一个数字6或更大,它会去:N
但每当我input6batch file退出。 我试过if %input% > 6 goto :N
但是它只是告诉我我要去Google。
@echo off :Start2 cls goto Start :Start title Frequently Used Websites echo Please select a website from the list echo with the corresponding key echo -------------------------------------- echo [1] Google echo [2] Wikipedia echo [3] Facebook echo [4] Youtube echo [5] Yahoo set input= set /p input= Choice: if %input%==1 goto Z if NOT goto Start2 if %input%==2 goto X if NOT goto Start2 if %input%==3 goto C if NOT goto Start2 if %input%==4 goto V if NOT goto Start2 if %input%==5 goto B if NOT goto Start2 if %input%>=6 goto N :Z cls echo You have selected Google pause start www.google.com exit :X cls echo You have selected Wikipedia pause start www.wikipedia.com exit :C cls echo You have selected Facebook pause start www.facebook.com exit :V cls echo You have selected Youtube pause start www.youtube.com exit :B cls echo You have selected Yahoo pause start www.Yahoo.com exit :N cls echo Invalid Selection! Try again pause goto :start2
尝试这个 :
if 3 gtr 2 @echo "biggger"
这输出:
"biggger"
其他运营商是:
EQU – 等于
NEQ – 不等于
LSS – 小于
LEQ – 小于或等于
GTR – 大于
GEQ – 大于或等于
if %var% geq 1
是最简单的方法
其实,你甚至不需要更大的功能。 所有你需要做的是添加
goto homepagename
那么如果没有if命令执行goto命令,那么你将被带到那里。
例如,这将修复你的代码:
@echo off :Start2 cls goto Start :Start title Frequently Used Websites echo Please select a website from the list echo with the corresponding key echo -------------------------------------- echo [1] Google echo [2] Wikipedia echo [3] Facebook echo [4] Youtube echo [5] Yahoo set input= set /p input= Choice: if %input%==1 goto Z if NOT goto Start2 if %input%==2 goto X if NOT goto Start2 if %input%==3 goto C if NOT goto Start2 if %input%==4 goto V if NOT goto Start2 if %input%==5 goto B if NOT goto Start2 if %input%>=6 goto N goto Start
你可以写这个(更容易)
@echo off :Start2 cls goto Start :Start title Frequently Used Websites echo Please select a website from the list echo with the corresponding key echo -------------------------------------- echo [1] Google echo [2] Wikipedia echo [3] Facebook echo [4] Youtube echo [5] Yahoo set /p input= Choice: if %input%==1 goto Z if %input%==2 goto X if %input%==3 goto C if %input%==4 goto V if %input%==5 goto B echo Invalid selection! echo. echo Press any key to go back! pause >nul cls goto start2 :Z cls echo You have selected Google pause start www.google.com exit :X cls echo You have selected Wikipedia pause start www.wikipedia.com exit :C cls echo You have selected Facebook pause start www.facebook.com exit :V cls echo You have selected Youtube pause start www.youtube.com exit :B cls echo You have selected Yahoo pause start www.Yahoo.com exit :N cls echo Invalid Selection! Try again pause goto start2