dotkb

    Cleanup a script on exit using trap

    (updated: )
    trap cleanup SIGINT SIGTERM ERR EXIT
    
    cleanup() {
      trap - SIGINT SIGTERM ERR EXIT
      # script cleanup here
    }
    

    Sources

    https://betterdev.blog/minimal-safe-bash-script-template/