oils-for-unix / oils

Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
http://www.oilshell.org/
Other
2.85k stars 159 forks source link

EXIT trap doesn't trigger when exiting from other signals #699

Open Crestwave opened 4 years ago

Crestwave commented 4 years ago

Used in #679. The great thing about Bash's trap is that you can trap EXIT and it will trigger on all other kinds of signals that make the program exit. It's a bit (very if you want to make it compatible with various POSIX shells) complicated to handle cleanup functions correctly without this, as simply trapping INT will prevent it from exiting on INT.

$ cat <<'EOF' >a
> trap 'echo foo' EXIT
> sleep 999
> EOF
$ bash a
^Cfoo

$ osh a
^C
$ 
andychu commented 4 years ago

Related: #619 for DEBUG trap