If GTR/LSS Operators in Batch
batch-file
Solution
Do not use double quotes `"!char_month!" GTR "11"` for numeric compare, in this case `cmd` will do a string compare. This should work:
@ECHO OFF &SETLOCAL
:last_char
set /p "char_month=Month (0-11): "
if %char_month% GTR 11 (
echo Enter a value between 0 and 11.
echo.
goto last_char
)
ECHO %char_month%
Problem
I have an increasingly large Batch file that uses `GTR`/`LSS` operators. The problem is that the `if` statements only permit me to enter certain values. In the following exemplar, typing in values of 2, 3 or 4 will return "Value too high." ``` :char_intb set char_points=30 set /a limit=!char_points!-3 set /p char_int="How many points for intelligence? " if "!char_int!" GTR "!limit!" echo Value too high. && goto char_intb if "!char_int!" GTR "!char_points!" echo Insufficient points. && goto char_intb if "!char_int!" LSS "1" echo Select a value greater than or equal to 1. && goto char_intb set /a char_points=!char_points!-!char_int! echo You now have !char_points! remaining. ``` There are others. As far as I've tested, it seems to only allow me to type 0 or 11. ``` set /p char_month="Month (0-11): " if "!char_month!" GTR "11" echo Enter a value between 0 and 11. && echo. && goto last_char ``` Where am I going wrong?