Skip navigation

JSI Tip 9975. How can I use 'IF this OR that' in a batch?


The IF statement has an ELSE clause, but no OR clause.

You can emulate an OR using either of the following methods:


set OK=N
FOR /F "Tokens=*" %%I in ('@echo \[%userName%\]^|Findstr /i "\[Jennifer\] \[Richard\] \[Jerry\] \[Alisa\]"') DO (
 set OK=Y
)
if "%OK%" EQU "Y" @echo Found.


OK=N
FOR %%I IN (\[Jennifer\],\[Richard\],\[Jerry\],\[Alisa\]) DO (
    if /i \[%USERNAME%\] 

%%I ( set OK=Y ) ) if "%OK%" EQU "Y" @echo Found.


NOTE: The separator can be any legal character, like ":

OK=N
FOR %%I IN ("Jennifer","Richard","Jerry","Alisa") DO (
    if /i "%USERNAME%"  %%I (
    set OK=Y
    )
)
if "%OK%" EQU "Y" @echo Found.



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish