← All Exercises
Trap for Cleanup on Exit
intermediatebash
Background
Trap ensures cleanup code runs regardless of how the script terminates.
Problem
Set up trap handlers to clean up temporary files when the script exits or is interrupted.
Input
Temporary files to clean up
Output
Guaranteed cleanup on exit
Sample tests
Sample 1
Input: trap cleanup EXIT
Expected: temp files removed
Your solution
Learning objective
Learn signal handling and resource cleanup in bash