LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Ignore/Disable Ctrl-C (SIGINT) in a shell script (https://www.linuxquestions.org/questions/programming-9/ignore-disable-ctrl-c-sigint-in-a-shell-script-780188/)

dctw 01-06-2010 01:31 AM

Ignore/Disable Ctrl-C (SIGINT) in a shell script
 
How do I write my trap statement in shell script to ignore SIGINT.
Reason being is that the script is used to update records in database. I want to avoid inconsistency in database when user presses Ctrl-C ...

The result should be
1. Totally ignore Ctrl-C (SIGINT) when user presses Ctrl-C
2. Continue with the rest of processing

choogendyk 01-06-2010 02:35 AM

trap is what you want.

see, for example, http://linuxdevcenter.com/pub/a/linux/lpt/44_12.html.

ForzaItalia2006 01-06-2010 04:51 AM

Hey,

try this:

trap "" 2

The number 2 stands for SIGINT (CTRL+C). This should then ignore the interrupt, at least bourne shell (sh) and bash :-)

- Andi -

dctw 01-11-2010 02:30 AM

It does not work..
The database still interrupts the operation when I press Ctrl-C

I think it is due to the handling within the database software, not on the shell ....


All times are GMT -5. The time now is 03:31 PM.