bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: exit somtimes not exit's the script


From: Bob Proulx
Subject: Re: exit somtimes not exit's the script
Date: Tue, 24 Jan 2006 09:53:41 -0700
User-agent: Mutt/1.5.9i

Paul Jarc wrote:
> vw@vonwolff.de wrote:
> >     a exit inside a loop inside a pipe exits's the loop and not the
> >     script. may bee a error.
> 
> This is normal.  Each element of a pipeline is run in a child process.

Yes.  Another more clear way of seeing this in the example would be
something like this which more clearly illustrates the pipeline aspect
of this issue.

    #!/bin/bash
    x() {
      exit 1
    }
    echo foo | x
    echo "after the pipeline"

> cat error.fil | while read a; do

Although I am sure this is reduced from a larger script the example
also has a "useless use of cat" as submitted.  Changing from a
multiprocess pipeline to a single process fixes both.  Here is a
slightly changed version of your example.

    #!/bin/bash
    x() {
      exit 1
    }
    echo -e "1\n2\n" >error.fil
    echo "start"
    while read a; do
        x
    done < error.fil
    # this should never be executed
    echo "if you see this, it's an error"

By the way, thanks for posting such a good example illustrating the
behavior.  Very nice.  Thanks.

Bob




reply via email to

[Prev in Thread] Current Thread [Next in Thread]