Next: , Previous: , Up: main   [Contents][Index]

22.3 Declaring exit codes

Some functions and global variables are provided to declare script’s exit codes. The MBFL declares its own exit codes starting from 100 and decreasing; we should declare our exit codes starting from 3 and increasing. The exit codes 0 and 1 are reserved for the functions exit_because_success() and exit_because_failure().

Function: mbfl_exit

Wrapper for the exit command that updates the internal state.

Variable: mbfl_main_pending_EXIT_CODE

Set by mbfl_exit() to the exit code this script is using. This variable might be accessed by atexit commands to appropriately react to an error condition.

Function: mbfl_main_is_exiting

Return true if the script is exiting. This function might be called by a location command being run by an atexit command.

Function: mbfl_main_declare_exit_code code name

Declare an exit code with value code and identifier name.

Function: mbfl_main_create_exit_functions

For each of the codes declared with mbfl_main_declare_exit_code(): create a function for the exit command using the numerical code; create an alias for the return command using the numerical code. For example, if a code is declared as:

mbfl_main_declare_exit_code 4 unexistent_file

a function is created with:

function exit_because_unexistent_file () { mbfl_exit 4; }

and an alias is created with:

alias return_because_unexistent_file='return 4'

the name of the function is the string exit_because_ followed by the exit code name; the name of the alias is the string return_because_ followed by the exit code name. The function may be used in the script to exit the process.

By default the exit code 0 is associated to the name success and the exit code 1 is associated to the name failure; so the following functions exist.

Function: exit_because_success
Function: exit_success

Exit the script with code 0.

Function: return_because_success
Function: return_success

Return with code 0.

Function: exit_because_failure
Function: exit_failure

Exit the script with code 1.

Function: return_because_failure
Function: return_failure

Return with code 1.

Function: exit_because_error_loading_library

Exit the script with code 100.

Function: return_because_error_loading_library

Return with code 100.

Function: mbfl_main_print_exit_code name

Print the code associated to name.

Next: , Previous: , Up: main   [Contents][Index]

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