Skip to main content

Batch Script Relational Operators

Relational Operators

Relational operators allow of the comparison of objects.

The following table lists the available relational operators.

OperatorDescriptionExample
EQUTests the equality between two objects2 EQU 2 will give true
NEQTests the difference between two objects3 NEQ 2 will give true
LSSChecks to see if the left object is less than the right operand2 LSS 3 will give true
LEQChecks to see if the left object is less than or equal to the right operand2 LEQ 3 will give true
GTRChecks to see if the left object is greater than the right operand3 GTR 2 will give true
GEQChecks to see if the left object is greater than or equal to the right operand3 GEQ 2 will give true

Example

The following code snippet shows how the various operators can be used.

Example of Relational Operators
@echo off 
set /A a=5
set /A b=10
if %a% EQU %b% echo A is equal to than B
if %a% NEQ %b% echo A is not equal to than B
if %a% LSS %b% echo A is less than B
if %a% LEQ %b% echo A is less than or equal B
if %a% GTR %b% echo A is greater than B
if %a% GEQ %b% echo A is greater than or equal to B
A is not equal to than B
A is less than B
A is less than or equal B