Page 1 of 1

Multiple checks in IF

Posted: 18 Mar 2011 04:52
by BVKmohan
Hi guys

Is there a way to perform multiple checks in single IF condition using the || or && operators

like example:

my script has to take hostnames which starts with either of these 5 characters : s; S; n; N; 10

What I am asking is can i put something like this

IF "%hostname:~0,1%" EQU "s" || "S" || "n" || "N" || "10" (do x) else (do y)

Re: Multiple checks in IF

Posted: 18 Mar 2011 11:10
by ChickenSoup
I think you would need multiple IF statements. You can eliminate case by using /I. But, a for loop like this can help clean it up.

Code: Select all

for %%a in (s n 10) do IF /I "%%a"=="%var1%" (do X) ELSE (do Y)


hope this helps get you on the right track

Re: Multiple checks in IF

Posted: 18 Mar 2011 11:16
by BVKmohan
wow ! I thought of for loop but not sure how to put it in :)
thanks for the help. appreciate it ... :lol: