Ravi Sir's Cards › AWS
trap cleanup
This revision card explains trap cleanup. It starts from the need that make a temp folder. It describes clean on any exit. The how-to section notes catch Ctrl+C. An example on the card is report errors.
Read card text
What this card says
Why do we need it?
Make a temp folder.
tmp=$(mktemp -d)
What is it?
Clean on any exit.
trap 'rm -rf "$tmp"' EXIT
How to do it
Catch Ctrl+C.
trap 'exit 130' INT
Example
Report errors.
trap 'echo line $LINENO' ERR