[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: A defer command as a bash loadable builtin
|
From: |
Léa Gris |
|
Subject: |
Re: A defer command as a bash loadable builtin |
|
Date: |
Thu, 25 Jun 2026 14:23:46 +0200 |
|
User-agent: |
Betterbird (Linux) |
Le 25/06/2026 à 00:36, Gregory Heytings écrivait :
Is this better than
trap_append () { trap "$(printf "%s\n$1" "$(trap -P "$2")")" "$2"; }
trap_prepend () { trap "$(printf "$1\n%s" "$(trap -P "$2")")" "$2"; }
Well those are clever but fragile:
$ trap_prepend () { trap "$(printf "$1\n%s" "$(trap -P "$2")")" "$2"; }
$ trap_prepend 'echo "Hello World!"' INT
$ trap -p INT
trap -- 'echo "Hello World!"' SIGINT
$ trap_prepend 'rm -f -- "$tmp"; printf "Cleanup done on %s\\n" "$tmp"' INT
trap -p INT
rap -- 'rm -f -- "$tmp"; printf "Cleanup done on echo "Hello World!"\n"
"$tmp"' SIGIN
This is not good!
Here with defer:
$ 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
--
Léa Gris
- A defer command as a bash loadable builtin, Léa Gris, 2026/06/22
- Re: A defer command as a bash loadable builtin, Gregory Heytings, 2026/06/24
- Re: A defer command as a bash loadable builtin, Léa Gris, 2026/06/25
- Re: A defer command as a bash loadable builtin,
Léa Gris <=
- Re: A defer command as a bash loadable builtin, Gregory Heytings, 2026/06/25
- Re: A defer command as a bash loadable builtin, Koichi Murase, 2026/06/25
- Re: A defer command as a bash loadable builtin, Léa Gris, 2026/06/26
- Re: A defer command as a bash loadable builtin, Koichi Murase, 2026/06/26
- Re: A defer command as a bash loadable builtin, Léa Gris, 2026/06/26
- Re: A defer command as a bash loadable builtin, Gregory Heytings, 2026/06/26