How to make bash execute a script every time it exits? -


i want execute commands every time exit bash, cannot find way it. there ~/.bash_logout file when logging out, use interactive shell instead of login shell, not useful purpose.

is there way this? thanks!

you can trap exit signal.

exit_handler () {   # code run on exit }  trap 'exit_handler' exit 

techinically, trap exit_handler exit work well. quoted emphasize first argument trap string passed eval, , not single function name. write

trap 'do_this; do_that; if [[ $picky == yes ]]; one_more_thing; fi' exit 

rather gather code single function.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -