Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if variable contains a piece of text in BATCH

Variable = %version%

This variable contains this = 5.13-update_01-01-2014

How can use the IF statement to check if the variable %version% contains the word 'update' ??

Thank you in advanced!

like image 435
ell Avatar asked Aug 07 '14 10:08

ell


1 Answers

A simple demo using conditional statements.

Look at this post (dbenham's answer) for a similar question How to conditionally take action if FINDSTR fails to find a string

C:\>set variable=5.13_01-01-2014

C:\>(echo %variable% | findstr /i /c:"update" >nul) && (echo Variable contains the string "update") || (echo Variable does not have the string "update")
Variable does not have the string "update"

C:\>set variable=5.13-update_01-01-2014

C:\>(echo %variable% | findstr /i /c:"update" >nul) && (echo Variable contains the string "update") || (echo Variable does not have the string "update")
Variable contains the string "update"

Cheers,G

like image 71
gbabu Avatar answered Oct 24 '22 04:10

gbabu