29.2 Driving script execution

Function: mbfl_main

The invocation to this function must be the last line of code in the script. It does the following:

  1. Register the value of the variable script_PROGNAME in the message module using the function mbfl_message_set_progname().
  2. Validate the semantic version specification hard–coded in the MBFL with the requirements of the script. If an error occurs in this step: terminate the script by calling exit_because_invalid_mbfl_version(), exit_because_invalid_mbfl_version.
    1. Check if a function named script_check_mbfl_semantic_version() exists. If it does not exist: move on to the next step. If it does exist: call it with MBFL’s semantic version specification string as single argument; if the function returns successfully: the version requirements are considered satisfied; otherwise exit the script by calling exit_because_invalid_mbfl_version().
    2. Check if the service variable script_REQUIRED_MBFL_VERSION is defined to a non–empty value, the value is expected to be a valid semantic version specification representing the minimum version required by the script; variables service.

      If an error occurs while parsing the semantic version specification in script_REQUIRED_MBFL_VERSION: terminate the script by calling exit_because_invalid_mbfl_version().

      If MBFL’s version is lesser than the one required by the script: terminate the script itself by calling exit_because_invalid_mbfl_version(); otherwise the version requirements are considered satisfied.

  3. Parse the command line arguments according to the command actions configuration; this step may change the selection of: main function, “before parsing options” function, “after parsing options” function; if no command actions are configured: nothing is done.

    This function searches for a declared action set with name MAIN: if such set exists, it expects the first command line argument to be an action identifier in the set.

  4. If it exists: invoke the function script_before_parsing_options() or the one selected by mbfl_main_set_before_parsing_options().
  5. Parse command line options with mbfl_getopts_parse().
  6. If it exists: invoke the function script_after_parsing_options() or the one selected by mbfl_main_set_after_parsing_options().
  7. Invoke the function whose name is stored in the global variable mbfl_main_SCRIPT_FUNCTION, if it exists, with no arguments; if its return value is non–zero: exit the script with the same code. The default value is main.
  8. Exit the script with the return code of the action function or zero.
Function: mbfl_main_set_main FUNCNAME

Select the main function storing FUNCNAME into mbfl_main_SCRIPT_FUNCTION.

Variable: mbfl_main_SCRIPT_FUNCTION

Global variable that holds the name of the custom main script function. The default name is main.

Function: mbfl_main_set_before_parsing_options FUNCNAME

The name of the function to be called right before parsing command line options. This value can be customised by both the MBFL and the user script.

The default function name is: script_before_parsing_options.

Function: mbfl_main_set_after_parsing_options FUNCNAME

The name of the function to be called right after parsing command line options. This value can be customised by both the MBFL and the user script.

The default function name is: script_after_parsing_options.


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