Welcome to libinclude's documentation!

To put it simply, libinclude is a shell library to import other shell scripts as libraries.

As a library we consider a simple shell script containing function and/or variable definitions. Libinclude offers you the possibility to use those kind of libraries in a comfortable manner. The usage is very close to the syntax of python's import statement. Functions (FUNC) and variables (VAR) in a library (MYLIB) can be simply included, but also imported in their own namespace (MYLIB_VAR, MYLIB_FUNC). It also provides the import MYLIB as ALIAS and the from MYLIB import FUNC statement, like in python. More about general usage...

To ensure the usability of the libraries across different OS and/or software configurations, libinclude provides some features to be utilized in the libraries. One can define dependencies with 3ed party programs, which will be checked while importing and returns a meaningful error message if not met. To adopt the library to different environments, conditional comments provide the possibility to include code blocks depending on defined conditions. It is also possible to run code on file inclusion by define a preprocessing block. More about library features...

Usage example

Here a simple example of a library file (mylib.sh):

# lib variables
MCOUNT='counting'
MDONE='done'

# lib function
loop () {
        local i
        i=0
        echo -n "$MCOUNT:"
        while [ $i -le $1 ]; do
                echo -n "$i,"
                i=$(($i+1))
        done
        echo "$MDONE!"
}

and a shell script where it is imported:

#!/bin/sh
. libinclude.sh
import mylib

# counting...
mylib_loop 10

# and 'en francaise'...
mylib_MCOUNT='compter'
mylib_MDONE='fini'
mylib_loop 3

which will return:

counting:0,1,2,3,4,5,6,7,8,9,10,done!
compter:0,1,2,3,fini!

Requirements

  • N/A, it is just a Bourne shell (sh) script.
  • Note: Libraries may come with their own dependencies!