[Top][All Lists]

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

Re: no reliable way to have SIGINT or exit exit a script?

From: tsurara
Subject: Re: no reliable way to have SIGINT or exit exit a script?
Date: Tue, 10 Sep 2002 19:58:00 -0700

> guess that bash isn't being sent SIGINT.  Do a system call trace to
> check.

Thanks for your reply.  That isn't the problem.  bash DOES get the signal, but 
it chooses just to stop whatever command is running, and continue on with the 
next command in the function, or to cycle the loop again.  You have to keep 
hitting ^C many times and hope that the succeeding commands don't get a chance 
to do any damage.  After all, you are hitting ^C because you do not want them 
to run....

OTOH, in the rare case where the script is at a read (with no traps set), it 
does nicely stop for you.  But if it is a read -p, it doesn't reset the 
terminal, so you have to kill the interactive shell or do an stty sane.

What I would like is for ^C by default to return the user to the command line, 
with nothing else happening.  Personally, I would like this to occur for loops 
at the command line also, not just scripts.

This also brings up error conditions.  I want to do something like this:

error () {
        echo $0: error: $@
        exit 1

myfunc () {
        if [...]
                error bad input

and have the whole shell script exit.  Typically the shell continues on in 
myfunc or its caller.  How do I get out of a shell script unconditionally? 

Note that nothing is in the bg here, and nothing is trapped.  My only reason 
for trapping is to try to fix this.

reply via email to

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