Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

But trap doesn't "stack" (like e.g. defer in Go) so if you do this it's not available for other purposes like cleanup


Yes. This also means that if you use a third-party shell library which uses “trap” internally (like shunit2), you can’t use “trap” in your own script at all.


not sure what you mean, you can have separate ERR and EXIT traps that run independently.


Yeah but each only exists once. If you wanna clean up on ERR and also use that trap for debugging you need to implement some janky layer on top of the trap.

(FWIW my take away from issues like this is always: Bash is not a serious programming language. If you are running up against these limitations in real life it's time to switch language. The challenge is really in predicting when this will happen _before_ you write the big script!)




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

Search: