#  cleanup temporary file in case of a keyboard interrupt (INT)
#  or a termination signal (TERM)
cleanup_temp() {
  [ -e "${tmpfile}" ] && command -p -- rm -f "${tmpfile}"
  exit 0
}
trap 'cleanup_temp' HUP INT PIPE TERM

tmpfile=$(mktemp) || {
  echo "$0: creation of temporary file failed!"
  exit 1
}
# use tmpfile ...
command -p -- rm -f -- "${tmpfile}"

# trap 'command -p -- rm -f "${tmpfile}"' HUP INT PIPE TERM
