MANPAGE

provides functions to import libraries or single functions in a Bourne shell (sh) script

SYNOPSIS

. libinclude.sh

include FILE

import FILE

import FILE as ALIAS

from FILE import FUNCTION

#if, #FI, #elif, #ELIF, #else, #ELSE, #fi, #FI

#preproccess_start, #PREPROCESS_START, #preproccess_END, #PREPROCESS_END

DESCRIPTION

libinclude.sh allows to include/import functions and or variables from external FILEs in a born shell script. The standard search path for FILE is $PATH, $HOME/bin and $HOME/lib.

To utilize this you have first to include the script itself like:

. libinclude.sh
include FILE
The FILE will simply be included after checking possible dependencies. Functions and variables are now accessible under the same name then used in FILE.
import FILE
Functions (FUNC) and variables (VAR) in FILE are now available under the name FILE_FUNC respectively FILE_VAR.
import FILE as ALIAS
Functions (FUNC) and variables (VAR) in FILE are now available under the name ALIAS_FUNC respectively ALIAS_VAR.
from FILE import FUNC
Only the function FUNC from FILE will be imported and available under the same name.
dependencies

On can define dependencies with 3ed party programs. For example, if you add the line:

"# depends on EXECUTABLE"

to the FILE, the availability of EXECUTABLE will be checked while the FILE becomes included/imported. If EXECUTABLE could not be found, an error message like:

"dependency 'EXECUTABLE' could not be met."

will be dropped.

conditional comments

You can utilize the following preprocessing comments:

#if, #elif, #else or #IF, #ELIF, #ELSE

the code block in the first condition which expression that return true (0) will be included in the script.

Conditional comments must be closed by:

#fi or #FI

This is a good way to include OS dependent functions.

preprocessing

It is also possible to run code on file inclusion. To start such a block you have to use:

#preproccess_start or #PREPROCESS_START

and it will be closed by:

#preproccess_end, #PREPROCESS_END

All code within this block will be executed and all output will be included in the script.

EXAMPLES

include MY_LIB

import MY_LIB

import MY_LIB as SOME_LIB

from MY_LIB import MY_FUNCTION


#if uname -a | grep 'Linux'
    SOME LINUX SPCIFIC CODE
#elif uname -a | grep 'FreeBSD'
    SOME FreeBSD SPECIFIC CODE
#else
    GENERIC CODE
#fi


#preprocesss_start
   SOME_CODE_WITH_OUTPUT_OR_NOT
#precocesss_end

SEE ALSO

sh(1)