Index

exit [reason]

Terminate execution of the containing script.

Optional Arguments:
String reason
If the user previously used the cleanup command to register a block of statements to be run when the script terminated, this optional value is assigned to the reason argument of this block. If no value is provided, the string, "exit" is substituted.

Example:
The following example terminates execution of the script after running any cleanup statements that the user registered. The reason argument of the block of cleanup statements is passed the value "exit".
 exit
Example of passing a reason to a block of cleanup statements.
The following example registers a print statement to be called on exit, then sometime later executes the "exit" command, saying that it is doing so because of a timeout. As a result the single cleanup statement prints out "Reason for exiting: timeout".
 cleanup {
   print "Reason for exiting: ", $reason,
 }
 ...
 exit "timeout"
Context:
This command is used to abort a script without executing any of the commands that follow it. There is an implicit exit statement at the end of every script, or when a script is aborted externally. If any cleanup statements have been registered with the cleanup command, they are executed before the script terminates.

Note that if an exit statement is executed from within a block of cleanup statements, this terminates the script immediately without either completing the remaining statements, or executing the list of cleanup statements again.


Martin Shepherd (9-Nov-1999)