Last active
September 2, 2018 09:18
-
-
Save LukeChannings/d64fd15c9e6367a02a63f5745a6a5116 to your computer and use it in GitHub Desktop.
catch.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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