|
| From: | Gregory Heytings |
| Subject: | Re: A defer command as a bash loadable builtin |
| Date: | Thu, 25 Jun 2026 12:42:33 +0000 |
$ enable -n defer; enable -f ./defer defer $ trap -- INT $ defer 'echo "hello world"' INT $ defer -p INT trap -- 'echo "hello world"' SIGINT $ defer 'rm -f -- "$tmp"; printf "Cleanup done on %s\\n" "$tmp"' INT $ defer -p INT trap -- 'rm -f -- "$tmp"; printf "Cleanup done on %s\\n" "$tmp" echo "hello world"' SIGINT
trap_prepend () { trap "$1
$(trap -P "$2")" "$2"; }
$ trap_prepend 'echo "Hello World!"' SIGINT
$ trap -p SIGINT
trap -- 'echo "Hello World!"
' SIGINT
$ trap_prepend 'rm -f -- "$tmp"; printf "Cleanup done on %s\n" "$tmp"' SIGINT
$ trap -p SIGINT
trap -- 'rm -f -- "$tmp"; printf "Cleanup done on %s\n" "$tmp"
echo "Hello World!"' SIGINT
| [Prev in Thread] | Current Thread | [Next in Thread] |