Hi,
Could someone give me a simple sintax overview to the various arguments involving "gtr" "lss" etc in the "if" command.
Any help would be greatly appreciated,
Rileyh
Help with the "gtr" "lss" etc arguments in the "if" command
Moderator: DosItHelp
Re: Help with the "gtr" "lss" etc arguments in the "if" comm
have you looked at IF /?
Re: Help with the "gtr" "lss" etc arguments in the "if" comm
@bob d
Yes I have looked at that and it is quite hard to understand.
Also it is very brief and has not much info on it
Rileyh
Yes I have looked at that and it is quite hard to understand.
Also it is very brief and has not much info on it
Rileyh
Re: Help with the "gtr" "lss" etc arguments in the "if" comm
See the code and test with different numbers to understand this:
If you want use the value as string use the quotation marks.
IF "%val1%" LSS "%val2%" ECHO The first word is alphabetically before the second word.
IF /I "%val1%" EQU "%val2%" ECHO Lowercase and uppercase are ignored - ABC is the same as abc
Robert
Code: Select all
@echo off
cls
echo.
echo Overview of the various comparison operations in the command IF
echo.
set /p val1= value 1:
set /p val2= value 2:
echo.
echo IF %val1% EQU %val2% (command if TRUE) ELSE command if FALSE
IF %val1% EQU %val2% (ECHO TRUE) ELSE ECHO FALSE
echo.
echo IF %val1% NEQ %val2% (command if TRUE) ELSE command if FALSE
IF %val1% NEQ %val2% (ECHO TRUE) ELSE ECHO FALSE
echo.
echo IF %val1% LSS %val2% (command if TRUE) ELSE command if FALSE
IF %val1% LSS %val2% (ECHO TRUE) ELSE ECHO FALSE
echo.
echo IF %val1% LEQ %val2% (command if TRUE) ELSE command if FALSE
IF %val1% LEQ %val2% (ECHO TRUE) ELSE ECHO FALSE
echo.
echo IF %val1% GTR %val2% (command if TRUE) ELSE command if FALSE
IF %val1% GTR %val2% (ECHO TRUE) ELSE ECHO FALSE
echo.
echo IF %val1% GEQ %val2% (command if TRUE) ELSE command if FALSE
IF %val1% GEQ %val2% (ECHO TRUE) ELSE ECHO FALSE
If you want use the value as string use the quotation marks.
IF "%val1%" LSS "%val2%" ECHO The first word is alphabetically before the second word.
IF /I "%val1%" EQU "%val2%" ECHO Lowercase and uppercase are ignored - ABC is the same as abc
Robert
Re: Help with the "gtr" "lss" etc arguments in the "if" comm
BASIC:
Explaination:
line1: if the first variable (VARIABLE1) is greater than the second (VARIABLE2) then skip to 1greaterthan2
line2: if the first variable (VARIABLE1) is less the second (VARIABLE2) then skip to 1lessthan2
line3: if the first variable (VARIABLE1) is equal the second (VARIABLE2) then skip to 1equal2
line4: if the first variable (VARIABLE1) is not equal the second (VARIABLE2) then skip to 1notequal2
line5: if the first variable (VARIABLE1) is less or equal the second (VARIABLE2) then skip to 1lessorequal2
line6: if the first variable (VARIABLE1) is greater or equal the second (VARIABLE2) then skip to 1greaterorequal2
Hope this helped!
-Exouxas
Code: Select all
line1: if VARIABLE1 gtr VARIABLE2 goto 1greaterthan2
line2: if VARIABLE1 lss VARIABLE2 goto 1lessthan2
line3: if VARIABLE1 equ VARIABLE2 goto 1equal2
line4: if VARIABLE1 neq VARIABLE2 goto 1notequal2
line5: if VARIABLE1 leq VARIABLE2 goto 1lessorequal2
line6: if VARIABLE1 geq VARIABLE2 goto 1greaterorequal2
Explaination:
line1: if the first variable (VARIABLE1) is greater than the second (VARIABLE2) then skip to 1greaterthan2
line2: if the first variable (VARIABLE1) is less the second (VARIABLE2) then skip to 1lessthan2
line3: if the first variable (VARIABLE1) is equal the second (VARIABLE2) then skip to 1equal2
line4: if the first variable (VARIABLE1) is not equal the second (VARIABLE2) then skip to 1notequal2
line5: if the first variable (VARIABLE1) is less or equal the second (VARIABLE2) then skip to 1lessorequal2
line6: if the first variable (VARIABLE1) is greater or equal the second (VARIABLE2) then skip to 1greaterorequal2
Hope this helped!
-Exouxas