130
BashWARNINGCommonExit CodeHIGH confidence

Script terminated by Control-C (SIGINT)

What this means

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).

Why it happens
  1. 1A user manually stopped the script's execution with Ctrl+C.
  2. 2The process was sent a SIGINT signal from another process (e.g., `kill -2 PID`).
How to reproduce

A long-running script is interrupted by the user.

trigger — this will error
trigger — this will error
#!/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

Trap the SIGINT signal for graceful shutdown
#!/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.

What not to do

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.

Sources

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Bash errors