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


22.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. Invoke mbfl_main_create_exit_functions(). Declaring exit codes.
  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.


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

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