EXIT

From STX Wiki
Jump to navigation Jump to search

What the various flavours of the EXIT statement have in common is that they all terminate something.

Terminate the shell

EXIT 0

This will terminate the shell immediately (which also implies that no result assignment is possible).

Terminate a definite number of call levels

EXIT level result_expression

This will return from level macro levels, and assign result_expression to the shell variable RESULT. The most common form is EXIT 1 result_expression, in which case only one (1) macro level will be left, causing control flow to return to the calling macro.

EXIT

The naked EXIT statement will return to the calling macro, i.e., leave one macro level, making the statement, with this respect, equivalent to EXIT 1. The naked EXIT statement does not set the RESULT variable.

Terminate an indefinite number of call levels

EXIT level result_expression

This will return from as many macro levels as needed to find a macro level where there is a non-empty local variable #onexitall defined.

See the script exitlevels.sts for a working example.