core_trap.sh 462 B

12345678910111213141516171819202122
  1. #!/bin/bash
  2. # LinuxGSM core_trap.sh module
  3. # Author: Daniel Gibbs
  4. # Contributors: https://linuxgsm.com/contrib
  5. # Website: https://linuxgsm.com
  6. # Description: Handles CTRL-C trap to give an exit code.
  7. moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
  8. fn_exit_trap() {
  9. if [ -z "${exitcode}" ]; then
  10. exitcode=$?
  11. fi
  12. echo -e ""
  13. if [ -z "${exitcode}" ]; then
  14. exitcode=0
  15. fi
  16. core_exit.sh
  17. }
  18. # trap to give an exit code.
  19. trap fn_exit_trap INT