Logical operators ("and", "or") in DOS batch

JoelFan picture JoelFan · Jan 26, 2010 · Viewed 454.3k times · Source

How would you implement logical operators in DOS Batch files?

Answer

paxdiablo picture paxdiablo · Jan 27, 2010

You can do and with nested conditions:

if %age% geq 2 (
    if %age% leq 12 (
        set class=child
    )
)

or:

if %age% geq 2 if %age% leq 12 set class=child

You can do or with a separate variable:

set res=F
if %hour% leq 6 set res=T
if %hour% geq 22 set res=T
if "%res%"=="T" (
    set state=asleep
)