Re: Control-C behavior



Brian Mac wrote:
hi,

look at using a trap..

trap 'exit 11' 2
for loop
trap 2

the first trap changes the default behaviour of the control-c to an
exit - you can set whatever value you want but i chose 11. put in your
for loop and then set the default trap value for a signal 2. you can
verify this by checking the exit status after running the break - echo
$?. it should be 11 (or whatever you chose to set it to)

That didn't seem to work for me, but simply putting the following at
the top of the script seems to work:

trap 'exit' INT TERM

hope this helps,
brian

uymqlp502@xxxxxxxxxxxxxx wrote:
I have a bash script with a for loop that starts other bash scripts (in
the foreground). When I hit Control-C, I want the top-level script to
terminate, but depending on the timing, sometimes one of the sub
scripts terminates instead. How can I ensure that the whole enchilada
will terminate? Thanks.

.



Relevant Pages