bash clean-up code 2 1

bash clean-up code 2

#!/bin/bash
scratch=$(mktemp -d -t tmp.XXXXXXXXXX)
function finish {
  rm -rf "$scratch"
}
trap finish EXIT

Here is what the above code is Doing:
1. Create a temporary directory
2. Create a function that will delete the temporary directory
3. Create a trap that will execute the function when the script exits

Similar Posts