I was asking myself if it is possible that when I terminate a bash script with crtl+c, the script would execute a last command before aborting, like delete a file which was created by that script?
You can trap the pseudo-signal EXIT
to execute something before exiting for any reason:
trap 'rm myfile' EXIT
or trap INT
to excecute a command on before exiting due to Control-C:
trap 'rm myfile' INT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With