Skip to content

Instantly share code, notes, and snippets.

@redianthus
Forked from cedws/defer.sh
Last active April 13, 2020 23:22
Show Gist options
  • Select an option

  • Save redianthus/5921e531737b69d67fdaa7c4317c0ba6 to your computer and use it in GitHub Desktop.

Select an option

Save redianthus/5921e531737b69d67fdaa7c4317c0ba6 to your computer and use it in GitHub Desktop.
Go-like defer 'keyword' for shell
#!/bin/sh
DEFER=
defer() {
DEFER="$*; ${DEFER}"
trap "{ $DEFER }" EXIT
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment