Skip to content

Instantly share code, notes, and snippets.

@WesselAtWork
Created May 26, 2023 16:35
Show Gist options
  • Select an option

  • Save WesselAtWork/f8b6c8f6e9a1d1646a0bf068a2145295 to your computer and use it in GitHub Desktop.

Select an option

Save WesselAtWork/f8b6c8f6e9a1d1646a0bf068a2145295 to your computer and use it in GitHub Desktop.
Cool noop catch on INT and TERM for traped EXIT
#!/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