Index

cleanup {statements}

Register a list of statements to be called when the script exits or is aborted.

Arguments:
{statements}
A list of statements to be executed when the script ends.

Example:
The following statement registers a block of statements to be executed when the calling script exits for any reason. Note the use of the "reason" variable, which contains the reason for the exit. In this case the value of this variable is supplied via the string argument of the exit statement. The "reason" variable is described in more detail below.
  cleanup {
    print "Reason for exit: ", $reason
    archive combine=10     # Save disk space by archiving slowly.
    signal/init quit       # Discard pending signals.
    mark remove, all       # Remove all feature markers.
    track stow             # Stow the telescope.
  }
  ...
  exit "All our sources have set."
Context:
Scripts can be terminated deliberately by calling the exit command, by reaching the end of the script, or by being aborted externally with the abort_schedule command. Particularly in the case of an external abort, it is usually desirable to tie up loose ends left by an incomplete script. The cleanup command allows one to register statements to perform this cleanup when the script terminates.

The block of cleanup statements is given access to a local String variable called "reason". This contains the reason for the exit. It either has the value presented to the exit command, or, if this argument is omitted, one of the following standard values:


Martin Shepherd (9-Nov-1999)