爲什麼是它下面給出的輸出我想到: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