Defining and Using Traps
As you will see, your script can trap for errors and the exit condition. These are probably the most commonly trapped-for events. Can other things be trapped? Let's answer that by examining the meaning of a trap.
Traps are typically described as asynchronous events. The event is asynchronous because of its unpredictability. An example is a Ctrl+C being pressed while your script is running. The event of the Ctrl+C is totally unpredictable from the perspective of your script. During one run, it might occur after 20 seconds; during another run, it might occur after 2 hours. And during a third run, it might not occur at all.
You may be thinking that a Ctrl+C causes an interrupt, not a trap. The trap is the action of reacting ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access