Reputation: 641
I need to write a batch file that will check if a variable contains specific value. I tried to do the following:
If "%%a"=="%%a:%pattern%" (
echo Yes
) else (
echo No
)
input example: %%a="bob binson" %patern%="binson"
I never get Yes printed! can anyone please tell what i missed or give an example of how (s)he would do it?
Thanks in Advance
Upvotes: 3
Views: 6527
Reputation: 70961
Substring operations are not available in for
replaceable parameters. You need to assign the data to a variable and then execute the operation on this variable
@echo off
setlocal enableextensions disabledelayedexpansion
>"tempFile" (
echo bob binson
echo ted jones
echo binson
)
set "pattern=binson"
for /f "usebackq delims=" %%a in ("tempFile") do (
echo data: %%a
set "line=%%a"
setlocal enabledelayedexpansion
if "!line:%pattern%=!"=="!line!" (
echo .... pattern not found
) else (
echo .... pattern found
)
endlocal
)
del /q tempFile
Upvotes: 1