为什么是它下面给出的输出我想到:Windows批处理文件:定义内从一个文件变量循环
@echo off
echo foobar > tmp.txt
SET /P a= < tmp.txt
echo %a%
FOR /F %%Q IN (tmp.txt) do set b=%%Q
echo %b%
即
foobar foobar
虽然下面的做没有:
@echo off
FOR /L %%n in (1,1,1) DO (
echo foobar > tmp.txt
SET /P a= < tmp.txt
echo %a%
FOR /F %%Q IN (tmp.txt) do set b=%%Q
echo %b%
)
即
ECHO is off.
ECHO is off.
一切我能找到给出了怎么办loop
环境以外的东西方向。
回答指导大卫Ruhmann
@echo off
setlocal ENABLEDELAYEDEXPANSION
FOR /L %%n in (1,1,1) DO (
echo foobar > tmp.txt
SET /P a= < tmp.txt
echo !a!
FOR /F %%Q IN (tmp.txt) do set b=%%Q
echo !b!
)
您需要为变量使用**延迟扩展**。请参阅['setlocal/?'](http://ss64.com/nt/setlocal.html)和[EnableDelayedExpansion](http://ss64.com/nt/delayedexpansion.html)。或[搜索StackOverflow](http://stackoverflow.com/search?q=%5Bbatch-file%5D+delayed+expansion) –
谢谢!我没有足够的声望来填写下面的答案,但是你给了我所需要的一切。 – ramzikai