Bash defer idiom
One use case of trap
in Bash is the following snippet:
tempfile=/tmp/tmpdata
function cleanup() {
rm -f $tempfile
}
trap cleanup EXIT
The highlighted line in particular might be considered an equivalent of a defer
statement in, say, Swift or Go.