Skip to content

Instantly share code, notes, and snippets.

@zapashcanon
Forked from cedws/defer.sh
Last active April 13, 2020 23:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zapashcanon/5921e531737b69d67fdaa7c4317c0ba6 to your computer and use it in GitHub Desktop.
Save zapashcanon/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