5.2 Exit codes and return codes

Some functions and global variables are provided to declare script’s exit codes. 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_declare_exit_code CODE NAME

Declare an exit code and a return code with value CODE and identifier NAME. This function creates a function and an alias equivalent to the following:

function exit_because_NAME () { mbfl_exit CODE; }
alias return_because_NAME='return CODE;'

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.

Function: mbfl_print_exit_code NAME

Print the code associated to NAME.

Variable: mbfl_EXIT_CODES_BY_NAME

A global associative array whose keys are the code names used as NAME argument to mbfl_declare_exit_code() and whose values are the code values used as CODE argument to mbfl_declare_exit_code().

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.

Alias: return_because_success
Alias: return_success

Return with code 0.

Function: exit_because_failure
Function: exit_failure

Exit the script with code 1.

Alias: return_because_failure
Alias: return_failure

Return with code 1.

In addition, the following functions are predefined; MBFL’s modules define other exit and return functions.

Function: exit_because_error_loading_library
Alias: return_because_error_loading_library

Exit or return with code 100.

Function: exit_because_invalid_function_name
Alias: return_because_invalid_function_name

Exit or return with code 91.

Function: exit_because_invalid_mbfl_version
Alias: return_because_invalid_mbfl_version

Exit or return with code 88.


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