batch file to assign a variable and compare with a string
I would like to know how I could achieve this, I tried few times with no luck.. I get a syntax error
I need to write a batch file to read the first line of a text, assign to a variable and then compare with a string.
bool.txt:
开发者_运维百科Hello
test.bat:
set Variable =< C:\bool.txt
if "%Variable%"=="Hello"
echo I am here
Thanks in advance SR
see help for
and help set
and then try this
for /f %%a in (bool.txt) do (
if "%%a"="Hello" echo I am here
)
You have an extra space after the variable name, therefore you're not setting the variable %Variable%
but %Variable %
.
Use
set /p Variable=< bool.txt
instead.
精彩评论