Re: Confusing bash behaviour



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.
.



Relevant Pages

  • Sol8 and EVA hangs
    ... Secure Path 3.0D is loaded for channel failover. ... retrying command ... # Adapter hard loop ID address to use on the fibre channel bus. ...
    (SunManagers)
  • Summary: Sol8 and EVA hangs
    ... Oct 8 11:00:41 proddb SCSI transport failed: reason 'aborted': ... retrying command ... # Adapter hard loop ID address to use on the fibre channel bus. ... # before reporting I/O errors. ...
    (SunManagers)
  • Re: Using foreach loop to create radiobutton menu
    ... Your foreach loop is not the problem, the problem is how you define the -command. ... The only possible thing the interpreter can do is substitute the current value of range, which is likely the last value once your loop exited. ... One choice is double quotes. ... The double quotes means that $range gets expanded while in the loop, long before the puts command actually runs. ...
    (comp.lang.tcl)
  • Re: Issue implementing Runtime.exec() with StreamGobbler
    ... So jloader basically calls LoaderAutomationRun.java (starts the loop) ... As you can see the last line, the New Command Executer never returned. ... If your test driver is hanging, I'd guess that the test process itself is ...
    (comp.lang.java.programmer)
  • Re: What does Ctrl+C really do
    ... loop) to fgetsthe user's commands. ... As posted before there is a signal handler taking care of that. ... I interprete "windows terminal" as a Command Shell in MS-WIndows, ... Shell detects that the telnet client has been gone it terminates itself. ...
    (comp.os.vxworks)