Script terminated by Control-C (SIGINT)
Exit code 130 indicates that a script was terminated by the user pressing Control-C. This sends the SIGINT (interrupt) signal. The exit code is calculated as 128 + 2 (the signal number for SIGINT).
- 1A user manually stopped the script's execution with Ctrl+C.
- 2The process was sent a SIGINT signal from another process (e.g., `kill -2 PID`).
A long-running script is interrupted by the user.
#!/bin/bash echo "Running a long task, press Ctrl+C to interrupt..." sleep 300
expected output
^C Exit: 130
Fix
Trap the SIGINT signal for graceful shutdown
WHEN The script needs to perform cleanup actions before exiting
#!/bin/bash trap 'echo "Caught SIGINT, cleaning up..."; exit 130' SIGINT echo "Running..." sleep 10 echo "Done."
Why this works
The `trap` builtin command allows you to catch signals and execute custom code, preventing the script from terminating immediately.
✕ Ignore the signal
If the script is performing a critical operation, ignoring the interrupt can leave the system in an inconsistent state. It is better to trap it and clean up.
GNU Bash Manual
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev