Exit hooks

When you want to add a command or a function to be called whenever your script ends (and you'd like it to be more error proof than calling the method at the end of your script file, you can do it like this:

#! /usr/bin/env bash

function my_exit_hook() {
  echo "Cleaning up after you"

trap my_exit_hook EXIT

Pretty cool, eh? You can read more on traps here.

Licensed under CC BY Creative Commons License ~ ✉ torstein.k.johansen @ gmail ~ 🐘 @skybert@emacs.ch ~ 🐦 @torsteinkrause