Is there a way to pass an OR through an IF statement?
Such as:
SET var=two
IF "%var%"=="one" OR "two" OR "three" ECHO The number is between zero and four.
Is there a way to pass an OR through an IF statement?
Such as:
SET var=two
IF "%var%"=="one" OR "two" OR "three" ECHO The number is between zero and four.
See duplicate question IF... OR IF... in a windows batch file where following solution proposed by @Apostolos
e.g.
I found to be the most straight forward and simple to use case in my batch scripts.
No.
If you need a more structured approach:
A bit late in the game, but nevertheless assuming if this might help anyone stumbling upon the question. The way I do this is using a combination of echo piped to findstr, this way:
Since findstr is an external command, I recommend not using this inside a loop which may go through 1000's of iterations. If that is not the case, this should solve what you are attempting to do instead of using multiple ifs. Also, there is nothing special in the choice of ":", just use a delimiter which is unlikely to be part of the value in the var variable.
Thanks to the rest of folks on pointing to another link which appears to have similar question, I will post this response there as well, just in case someone stumbles upon that question and doesn't quite reach here.