Creating modular scripts


If you want to create modular scripts, that expand upon the actual capabilities of the script itself, then you can make use of the do_hook function in the following script:

#!/bin/sh

do_hook()
{
#
# The modular hook begings here. Check whether or not there are files in the folder ${HOME}/bin/modular/.bu
# If there are files, then source them, thus extending the functionality of the script which implements this function.
#

if [ -d ${HOME}/bin/modular/.bu ] ; then
	cd $HOME/bin/modular/.bu
	BU_CONTENTS=*
	if [ -n "$BU_CONTENTS" ] ; then
		echo "Sourcing files from folder ${HOME}/bin/modular/.bu:"
		for i in $BU_CONTENTS
		do
			echo "Sourcing ${HOME}/bin/modular/.bu/$i"
			source ./$i
			echo
		done
		echo "Done sourcing ${HOME}/bin/modular/.bu."
	fi
fi

#
# Modular hook ends here.
#
}

### Entry point
echo "hello before hook"

do_hook

echo "hello after hook"
exit 0