Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If greater than batch files

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 :N but whenever I type 6 the batch file exits. I have tried if %input% > 6 goto :N but it just tells me I am going to 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 
like image 894
gm95 Avatar asked Feb 14 '12 14:02

gm95


People also ask

Can you use if statements in batch files?

One of the common uses for the 'if' statement in Batch Script is for checking variables which are set in Batch Script itself. The evaluation of the 'if' statement can be done for both strings and numbers.

What does >> mean in batch?

On using in a batch file with just > or >> to redirect standard output to a file or a device like NUL without @echo off the Windows command processor shows the line how it is executed after parsing it. You can see that a space and 1 is inserted left to > .

What is @echo off in batch script?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.


2 Answers

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

Reference

  • Microsoft TechNet | Windows Server 2012 | Command-line Reference: If (Archived here)
  • SS64: If (Archived here)
like image 155
Royi Namir Avatar answered Oct 18 '22 12:10

Royi Namir


    if %var% geq 1 

is the easiest way

like image 29
KaushTheDonOfAllOfThemAllHaHa Avatar answered Oct 18 '22 11:10

KaushTheDonOfAllOfThemAllHaHa