#!/usr/bin/env bash
set -euo pipefail
WORK="$(mktemp -d)"
echo "Working in $WORK"
cleanup() {
local rc=$?
rm -rf "$WORK"
echo "Cleaned up (exit code $rc)"
exit $rc
}
# EXIT covers normal exit AND errexit
# INT covers Ctrl-C; TERM covers `kill`
trap cleanup EXIT INT TERM
# Do work that might fail — cleanup runs no matter what
cd "$WORK"
curl -s https://example.com -o data.html
process data.html
Create a free account and build your private vault. Share publicly whenever you want.