Created
May 26, 2023 16:35
-
-
Save WesselAtWork/f8b6c8f6e9a1d1646a0bf068a2145295 to your computer and use it in GitHub Desktop.
Cool noop catch on INT and TERM for traped EXIT
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/ash | |
| trap : INT TERM | |
| # your code here... | |
| touch /tmp/tmpfile | |
| trap '{ rm /tmp/tmpfile; }' EXIT | |
| touch /tmp/otherthing | |
| trap '{ rm /tmp/otherthing; }' EXIT | |
| # more code... | |
| #Both tmp files will be deleted after NORMAL EXECUTION + EXITS and if a ^C or a SIGKILL is recieved. | |
| #I think this works becuase the noop counts as a "normal" exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment