windows 如果大于批处理文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9278614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 09:13:52  来源:igfitidea点击:

If greater than batch files

windowsbatch-filecmd

提问by gm95

I wrote a simple batch file to run Frequently Used websites based on a number selection. Here's the code I have. I am trying to set it so if someone inputs a number 6 or greater it will go to :Nbut whenever I type 6 the batch file exits. I have tried if %input% > 6 goto :Nbut it just tells me I am going to Google.

我写了一个简单的批处理文件来运行基于数字选择的常用网站。这是我的代码。我正在尝试设置它,以便如果有人输入数字 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

回答by Royi Namir

try this:

尝试这个:

if 3 gtr 2 @echo "biggger"

This outputs:

这输出:

"biggger"

enter image description here

在此处输入图片说明

The other operators are:

其他运营商是:

EQU - equal
NEQ - not equal
LSS - less than
LEQ - less than or equal
GTR - greater than
GEQ - greater than or equal

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

Reference

参考

回答by KaushTheDonOfAllOfThemAllHaHa

    if %var% geq 1

is the easiest way

是最简单的方法

回答by user3674709

Actually, you don't even need a greater feature. All you need to do is add

实际上,您甚至不需要更大的功能。您需要做的就是添加

goto homepagename

Then you will be taken there if none of the if commands execute a goto command.

如果没有任何 if 命令执行 goto 命令,那么您将被带到那里。

For example, this will fix your code:

例如,这将修复您的代码:

@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

回答by Eli Pesso

You can write this (easier)

你可以写这个(更容易)

@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