Scripts often choose different cleanup behavior for different signals. A case statement keeps those routes explicit.

Program

Play the script to choose a signal name and see the action a script would plan for it.

signal_route.sh
#!/usr/bin/env bash

signal=
case "$signal" in
    INT) action="stop-from-keyboard" ;;
    TERM) action="graceful-shutdown" ;;
    HUP) action="reload-config" ;;
esac
echo "$signal:$action"
#!/usr/bin/env bash

signal=
case "$signal" in
    INT) action="stop-from-keyboard" ;;
    TERM) action="graceful-shutdown" ;;
    HUP) action="reload-config" ;;
esac
echo "$signal:$action"
#!/usr/bin/env bash

signal=
case "$signal" in
    INT) action="stop-from-keyboard" ;;
    TERM) action="graceful-shutdown" ;;
    HUP) action="reload-config" ;;
esac
echo "$signal:$action"
signal A signal is a small named notification sent to a process.
case route `case` makes signal-to-action decisions easy to scan.
modeled action This example prints the planned action instead of sending real signals.