Reputation: 31
I'm kinda newbie to CMD. I was wondering; is it possible to check for multiple criteria on different variables at once, using IF command? I mean, what would be the syntax of IF command if you wanted to check 2 different variables at the same time matching the given criteria? I mean does that thing exist? Something like:
IF %%variable1%% == variableone AND %variable2% == variabletwo do stuff
I've been trying to sort this out myself, but couldn't find a way to to doit. Kept getting errors. Maybe there's something wrong in the syntax of the command or I'm missing something.
Upvotes: 1
Views: 110
Reputation: 56208
Another way to implement a logical AND:
if "%variable1%@%variable2%" == "variableone@variabletwo" goto :dostuff
Note1: @
is just a delimiter to get sure foo
+bar
and foob
+ar
are not treated the same. (foo@bar
vs. foob@ar
) Without a delimiter, both would give foobar
.
Note2: the quotes prevent a syntax error when one side of the comparison is empty
Note3: I assume, %%variable1%%
is a typing error and should read %variable1%
Upvotes: 1
Reputation: 1774
You cannot use logical operators, but you can do this:
IF %%variable1%% == variableone IF %variable2% == variabletwo GOTO :DOSTUFF
or
IF %%variable1%% == variableone (
IF %variable2% == variabletwo (
rem do stuff here
)
)
Upvotes: 1