DOS – Multiple IF conditions in a batch file

--> (Word) --> (PDF) --> (Epub)
This article has been published [fromdate]

Is there a way to say something like:

if %1 == 1 or %1 == 2

in a batch file?

Or, even better, if I could specify a set of candidate values like:

if %1 in [1, 2, 3, 4, ... 20]

SOLUTION

One way to implement logical-or is to use multiple conditionals that goto the same label.

if %1 == 1 goto :cond
if %1 == 2 goto :cond
goto :skip
:cond
someCommand
:skip

To test for set membership, you could use a for-loop:

for %%i in (1 2 3 4 ... 20) do if %1 == %%i someCommand

Note: that == is the string equality operator. equ is the numeric equality operator.

SOURCE

LINK (Stackoverflow.com)

LANGUAGE
ENGLISH