Multiple checks in IF

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
BVKmohan
Posts: 4
Joined: 16 Mar 2011 05:57
Location: mumbai
Contact:

Multiple checks in IF

#1 Post by BVKmohan » 18 Mar 2011 04:52

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)

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: Multiple checks in IF

#2 Post by ChickenSoup » 18 Mar 2011 11:10

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

BVKmohan
Posts: 4
Joined: 16 Mar 2011 05:57
Location: mumbai
Contact:

Re: Multiple checks in IF

#3 Post by BVKmohan » 18 Mar 2011 11:16

wow ! I thought of for loop but not sure how to put it in :)
thanks for the help. appreciate it ... :lol:

Post Reply