cleanup {statements}
Register a list of statements to be called when the script exits or is aborted.
{statements}
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."
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:
"abort"
- The script was aborted via the abort_schedule command.
"end"
- The script finished normally.
"exit"
- An exit
command was executed without a
reason
argument being given.