Page 1 of 1
why does this FOR statement output %f and this one doesn't?
Posted: 09 Aug 2011 18:47
by taripo
x2.bat outputs %f, and x3.bat doesn't. Why?
C:\>type x2.bat <ENTER>
for %%f in (a b) do (
echo %%f
echo tw
)
C:\>x2 <ENTER>
C:\>for %f in (a b) do (
echo %f
echo tw
)
C:\>(
echo a
echo tw
)
a
tw
C:\>(
echo b
echo tw
)
b
tw
C:\>
C:\>type x3.bat <ENTER>
for %%f in (a b) do (
echo %%f
)
C:\>x3 <ENTER>
C:\>for %f in (a b) do (echo %f )
C:\>(echo a )
a
C:\>(echo b )
b
C:\>
---
Re: why does this FOR statement output %f and this one doesn
Posted: 09 Aug 2011 22:49
by dbenham

Both outputs look fine to me. They each echo a and b which corresponds to %f.
Dave Benham
Re: why does this FOR statement output %f and this one doesn
Posted: 09 Aug 2011 23:25
by taripo
dbenham wrote::?

Both outputs look fine to me. They each echo a and b which corresponds to %f.
Dave Benham
x2.bat has an extra iteration that x3.bat doesn't have, look at x2.bat's output before the iteration that echos 'a'. I'd like to know what's happening there. Why that is.
Re: why does this FOR statement output %f and this one doesn
Posted: 09 Aug 2011 23:30
by taripo
oh my mistake, I mixed up display of execution of the for, with the output of the for..
I only made a one line difference between x2.bat and x3.bat (without echo tw) and the output looked a bit different 'cos cmd put the ( ) on one line for x3.bat . and I got a bit confused with the pattern.. sorry.
Re: why does this FOR statement output %f and this one doesn
Posted: 09 Aug 2011 23:39
by dbenham
I still don't see the difference, apart from the obvious absence of "echo tw".
Here are the outputs side by side
Code: Select all
C:\>x2 <ENTER> | C:\>x3 <ENTER>
|
C:\>for %f in (a b) do ( | C:\>for %f in (a b) do (echo %f )
echo %f |
echo tw |
) |
|
C:\>( | C:\>(echo a )
echo a | a
echo tw |
) |
a |
tw |
|
C:\>( | C:\>(echo b )
echo b | b
echo tw |
) |
b |
tw |
|
C:\> | C:\>
Your last post came while I was editing my postDave Benham