Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between == and EQU operator?

What is the difference between == and EQU operator in Batch?

Below is just a sample snippet:

if !one! EQU - (
    if !one!==!two! (
        if !two!==!three! (
            goto endgame
        )
    )
)
like image 491
Yolo-cell-hash Avatar asked Feb 02 '26 14:02

Yolo-cell-hash


1 Answers

If EQU finds that the two things being compared are valid integers (in octal, decimal, or hexadecimal), then an integer comparison will be performed.

For example, if 0x64 EQU 100 (echo yes) else (echo no) returns yes because 64 in hexadecimal is equivalent to 100 in decimal.

If either of the two things being compared cannot possibly be a valid integer (the number 09, for example, which would be octal except that 9 isn't a valid octal digit), then a string comparison is performed.

== only runs a string comparison, so if 0x64==100 (echo yes) else (echo no) returns no because the two strings are different.

In terms of simple string comparisons, the two operators act in essentially the same way, but EQU takes a few clock cycles longer because it first has to try to convert the two items to integers.

like image 109
SomethingDark Avatar answered Feb 04 '26 06:02

SomethingDark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!