[batch-file] Less than or equal to

Using the pause command I found that the error is in the first line of this code:

if %choice% == 1 if %energy% => %m2enc% set /a enemhp=%enemhp%-%m1hpd%+%earmr%
pause
set /a energy= %energy%-%m1enc%
set /a hp= %hp%-%edefense%
set /a defense= %defense%+1
goto battle

So don't say that I forgot to set the energy and the m2enc, because I did just in a different section, I also tried replacing %energy% with 10 and m2enc% with 1 and it still didn't work, I tried replacing the => with >= and with LSQ (apparently an alternative for less than or equal too) So I would like to know whats wrong with this part.

This question is related to batch-file

The answer is


In batch, the > is a redirection sign used to output data into a text file. The compare op's available (And recommended) for cmd are below (quoted from the if /? help):

where compare-op may be one of:

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

That should explain what you want. The only other compare-op is == which can be switched with the if not parameter. Other then that rely on these three letter ones.


You can use:

EQU - equal

NEQ - not equal

LSS - less than

LEQ - less than or equal

GTR - greater than

GEQ - greater than or equal

AVOID USING:

() ! ~ - * / % + - << >> & | = *= /= %= += -= &= ^= |= <<= >>=


There is no => for if.
Use if %energy% GEQ %m2enc%

See if /? for some other details.