Why is having a string value greater than (GTR
) or greater or equal than (GEQ
) a number always return the value true
?
For example this:
Set var=abc
if %var% gtr 0 echo true
or
if %var% geq 0 echo true
No matter what "var" the number of comparison is, the result is the same. Why?
Also why is using LSS
or LEQ
(Less than, Less or Equal than) the result is always false
?
I wanted to create a simple script only allowing numeric values up to 31 and only one letter like this:
:MENU
CLS
echo. Insert Day or "X" to return to another script
Set /p variable=Insert date:
for /f "delims=0123456789" %%a in ("%variable%") do set variable=%%a
if not defined %variable% goto :MENU
if /i %variable% equ X goto :otherscript2
if %variable% equ 0 goto :MENU
if %variable% gtr 31 goto :MENU
:: Continue script
.
.
Using this script, whenever the number is between 1-31, it will continue, if there are letters, it will return to :MENU
but if it's X
then it goes to :otherscript2
. It's working as intended and I figured out it is because of the
if %variable% gtr 31 goto :MENU
which means
if <string> gtr 31 goto :MENU // where <string> = any string except the X
But I don't understand why it works like this.
Thank you in advance.