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


1.2 Reliable run–time loading

A more reliable way to load the library is:

declare mbfl_INTERACTIVE=no
declare mbfl_LOADED=no
declare mbfl_HARDCODED=
declare mbfl_INSTALLED=$(type -p mbfl-config &>/dev/null && mbfl-config) &>/dev/null

declare item
for item in "$MBFL_LIBRARY" "$mbfl_HARDCODED" "$mbfl_INSTALLED"
do
    if test -n "$item" -a -f "$item" -a -r "$item"
    then
        if source "$item" &>/dev/null
        then
	    declare -r mbfl_LOADED_LIBRARY=$item
	    break
        else
            printf '%s error: loading MBFL file "%s"\n' "$script_PROGNAME" "$item" >&2
            exit 100
        fi
    fi
done
unset -v item
if test "$mbfl_LOADED" != yes
then
    printf '%s error: incorrect evaluation of MBFL\n' "$script_PROGNAME" >&2
    exit 100
fi

where the value of mbfl_HARDCODED can be the pathname of a known location in which to find the library. This code:

  1. Looks for the pathname in the MBFL_LIBRARY variable, to allow us to explicitly select the file from the command line; example:
    $ MBFL_LIBRARY=/path/to/libmbfl.sh script.sh
    
  2. Looks in some known directory; for example a subdirectory of a software package that we have distributed.
  3. As a last resort tries to evaluate the mbfl-config script to pick up a library installed on the system.

We see that the output of the source command is discarded: this is because we assume that:

This code is included in the MBFL distribution in the src/lib/loader.sh file; we can also automatically include it in a script with the preprocessor macro mbfl_library_loader.


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

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