Skip to content
Justice Tech School

trap

trap runs code on signals or when the script exits.

Example
cleanup() { echo "cleaning"; }
trap cleanup EXIT
echo "working"
exit 0

Result

working
cleaning

Exercise

Run at exit.

trap f 

Quiz Test

When does trap EXIT run?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.