Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Batch Script to find a variable contains string or Variable has values

I have a Variable in my Batch %rev%

I need to check whether it contains a string "new" or it has a value of random numbers in it.

Any help Appreciated.

I was trying with the below code but it doesnt work.

if /I "%rev%"=="new" (
echo String has new
) else (
echo it doesnt has new
)
like image 249
John Avatar asked Oct 31 '25 09:10

John


1 Answers

you can try with :

if /I "%rev:new=%" neq "%rev%" (
echo String has new
) else (
echo it doesnt has new
)

or with (a little bit slower):

(echo(%rev%)|find /i "new" >nul && (
  echo String has new
)||(
  echo it doesnt has new 
)
like image 85
npocmaka Avatar answered Nov 02 '25 01:11

npocmaka