Command file for assigning a variable and comparing with a string

I would like to know how I could achieve this, I tried several times, no luck .. I get a syntax error

I need to write a batch file to read the first line of text, assign it to a variable, and then compare with the line.

bool.txt:

Hello

test.bat:

set  Variable =< C:\bool.txt
if "%Variable%"=="Hello"
echo I am here

Thanks in advance SR

+3
source share
2 answers

cm. help for, and help setthen try

 for /f %%a in (bool.txt) do (
     if "%%a"="Hello" echo I am here
 )
+5
source

You have extra space after the variable name, so you are not setting the variable %Variable%, but %Variable %.

Using

set /p Variable=< bool.txt

instead.

0
source

All Articles