#!/bin/sh set -eu cleanup() { rm -rf "$tempdir" } tempdir="$(mktemp -d)" trap cleanup EXIT echo foo > "$tempdir/foo.txt" echo "$tempdir"