Bash Shell Scripting Disable Control-C [ CTRL+C ] Keys

Bash Shell Scripting Disable Control-C [ CTRL+C ] Keys

To disable the Control-C (CTRL+C) keys in a Bash shell script, you can use the trap built-in command to specify a command to execute when the SIGINT signal is received.

The SIGINT signal is generated when the Control-C keys are pressed. By default, the SIGINT signal terminates the script or command that is currently running.

To disable the Control-C keys in a Bash shell script, you can use the trap built-in with the SIGINT signal and an empty command. For example:

# Disable Control-C keys
trap '' SIGINT

# Your script code here

# Enable Control-C keys
trap - SIGINT
Sour‮www:ec‬.lautturi.com

This will disable the Control-C keys while the script is running, and re-enable them when the script exits.

It is important to note that the Control-C keys can still be used to terminate the script if it is running in a terminal that is not connected to the script, such as when the script is running in the background or when it is run using the nohup command.

For more information about the trap built-in and the SIGINT signal, you can consult the documentation for the Bash shell.

Created Time:2017-10-27 14:56:35  Author:lautturi