Skip to main content
1 of 3
pLumo
  • 23.2k
  • 2
  • 43
  • 70

You can run the command in a subshell and trap on SIGINT running kill 0 to kill the subshell only.

select opt in a b; do
    case $REPLY in
      1)
        (
          trap "kill 0" SIGINT
          sleep 10
        )
        ;;
      2)
        sleep 10
        ;;
    esac
done
  • Selecting (1) will let you use Ctrl+c without killing the menu.
  • Selecting (2) and pressing Ctrl+c will kill the menu, too.
pLumo
  • 23.2k
  • 2
  • 43
  • 70