Hacker News new | past | comments | ask | show | jobs | submit login

This is unnecessary. The EXIT trap fires on any exit from the shell, not just graceful exit.



The behavior varies with shell:

    $ cat test_trap 
    trap 'echo exiting' EXIT 
    kill $$
    
    $ bash test_trap
    exiting
    Terminated
    
    $ ksh test_trap
    exiting
    Terminated

    $ mksh test_trap
    exiting
    
    $ dash test_trap
    Terminated
    
    $ zsh test_trap
    Terminated


This article is specifically about Bash. I'm not surprised that `trap` behavior varies per shell, and I'd recommend reading the documentation on it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: