You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Agree. I think this is a cool idea. In the case of functions would something like the following work?
my_func() {
defer rm -rf "$TMP_DIR"
TMP_DIR="$(mktemp -d)"# do stuff in $TMP_DIR...
}
# $TMP_DIR was deleted when my_func() is out-of-scope
If so, I could see it being very nice to have. Not sure how challenging it would be to implement it in such a way that if you had something like set -u in your script, it could handle TMP_DIR being set later, but ideally that would work too.
What will be the impact of having a new keyword
defer
that defers the execution of a given command.global shell
Output:
functions
it works in functions too:
Output:
sub-shells
works on subshells and command substitution as well:
Output:
command substitution
Output:
This feature is inspired by the Go programming language.
Thoughts: @simonw @ianwalter @pohart @tangowithfoxtrot @vanodevium
The text was updated successfully, but these errors were encountered: