Skip navigation

JSI Tip 10121. More on how can I use 'IF this OR that' in a batch?


We previously explained how to use 'IF this OR that' in a batch.

Here is an additional method that makes use of the built-in FINDSTR command:

Example:

To determine of a parameter is equal to Jennifer or Richard or Jerry or Alisa

call :isequal Richard
goto :EOF
:isequal
@echo \[Jennifer\] \[Richard\] \[Jerry\] \[Alisa\] | findstr /c:"\[%1\]" >nul
if %errorlevel% equ 0 (
  @echo %1 found.
 ) ELSE (
  @echo %1 NOT found. 
)
NOTE: This routine is case sensitive. If you wish to make it case insensitive, replace findstr /c:"\[%1\]" with findstr /i /c:"\[%1\]"



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