Re: Confusing bash behaviour
- From: Joe Beanfish <joe@xxxxxxxxxx>
- Date: Tue, 10 Aug 2010 13:18:05 -0400
On 08/09/10 16:17, Vilmos Soti wrote:
Hello,
This is a solved problem for me, but I think people should be aware of
this strange and confusing bash behaviour.
for x in `command`; do command-list; done
command | while read x; do command-list; done
are not interchangeable.
The problem arises if in the command-list there is a command which reads
from stdin. In that case, the for loop behaves as expected, but in the
case of a while loop, the stdin reading program will consume some or
all of the remaining lines fed into the while loop.
Correct. In the first example "command" is run to completion and it's
output placed onto the for command line.
In the second example "command" feeds one line at a time into the pipe
which reads one with "read". The rest are available and can be consumed
by command-list.
.
- References:
- Confusing bash behaviour
- From: Vilmos Soti
- Confusing bash behaviour
- Prev by Date: Re: Wanted window restore feature in nautilus
- Next by Date: Re: alternate data stream
- Previous by thread: Re: Confusing bash behaviour
- Next by thread: Re: Confusing bash behaviour
- Index(es):
Relevant Pages
|