开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜