如果大于批处理文件

时间:2012-02-14 14:28:38

标签: windows batch-file cmd

我写了一个简单的批处理文件,根据数字选择运行常用网站。这是我的代码。我试图设置它,所以如果有人输入数字6或更高,它将转到:N,但每当我输入6时,批处理文件退出。我试过if %input% > 6 goto :N,但它只是告诉我我要去谷歌。

@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

4 个答案:

答案 0 :(得分:85)

试试这个:

if 3 gtr 2 @echo "biggger"

输出:

"biggger"

enter image description here

其他运营商是:

  

EQU - 等于
  NEQ - 不等于
  LSS - 少于
  LEQ - 小于或等于
  GTR - 大于
  GEQ - 大于或等于

参考

答案 1 :(得分:5)

    if %var% geq 1

是最简单的方式

答案 2 :(得分: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

答案 3 :(得分:0)

你可以写这个(更简单)

@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