core_trap.sh 420 B

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