5.3 Running scripts at exit–time

Bash allows us to execute a command whenever it exits by issuing the command:

trap <script> EXIT

the atexit MBFL module uses this mechanism to register, forget and run multiple commands.

Function: mbfl_atexit_enable
Function: mbfl_atexit_disable

Register or delete mbfl_atexit_run() as command for the EXIT event. We must call this function first if we want to use this module.

Function: mbfl_atexit_register HANDLER
Function: mbfl_atexit_register HANDLER IDVAR

Register a new HANDLER command. If the optional argument IDVAR is present, it must be the name of a variable in the scope of the caller: store into such variable a unique identifier associated to the handler.

Function: mbfl_atexit_forget ID

Remove the, previously registered, handler command associated to ID. If no handler is associated to it: nothing happens.

Function: mbfl_atexit_run

Run all the registered handlers, from the last registered to the first. Whenever a handler is run: it is removed from the internal registry.

Function: mbfl_atexit_clear

Remove all the registered handlers from the internal registry. This renders invalid all the handler identifiers that were created.


This document describes version 3.0.0-devel.9 of Marcos Bash Functions Library.