Skip to content

Instantly share code, notes, and snippets.

@LukeChannings
Last active September 2, 2018 09:18
Show Gist options
  • Save LukeChannings/d64fd15c9e6367a02a63f5745a6a5116 to your computer and use it in GitHub Desktop.
Save LukeChannings/d64fd15c9e6367a02a63f5745a6a5116 to your computer and use it in GitHub Desktop.
catch.sh
#!/usr/bin/env sh
set -eaf -o posix -o pipefail
TMP="/tmp/foo-$(date +%s)"
setup () {
mkdir -p "$TMP"
cd "$TMP" || exit 1
}
cleanup () {
[ $? -ne 0 ] && echo "An error occurred and the script had to exit early."
echo "Cleaning up"
rm -rf "$TMP"
}
trap cleanup EXIT
setup
ls /root/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment