This is overly complex for a learning exercise.
I would recommend that you learn POSIX shell scripting first, then add bash extras as you find them necessary or helpful.
I have gone over the top level script from the zip file and made a few comments:
#!/bin/sh
Since you use bash-specific code in the script, you should specify
bash in the shebang.
# Setting bash options
set -o errexit
set -o nounset
set -o pipefail
# Getting full path to current script
prg=$0
if [ ! -e "$prg" ]; then
case $prg in
(*/*) exit 1;;
(*) prg=$(command -v -- "$prg") || exit;;
esac
fi
There is rarely, if ever, a good reason to need the location of the running script.
When there is, it should be done in a wrapper that is in a standard location, e.g., /usr/local/bin/linsey, and contain something like:
cd /path/to/working/directory
./f-linsey.sh
# Setting variables
FL_THIS_DIR=$(
cd -P -- "$(dirname -- "$prg")" && pwd -P
) || exit
Why do you need $FL_THIS_DIR?
In a POSIX shell (which bash is), the current directory is always in ${PWD}.
FL_LIB_DIR="${FL_THIS_DIR}/lib"
FL_FLINSEY_VERSION="1.0"
# Loading libraries
if [ ! -d "${FL_LIB_DIR}" ];
then
echo "ERROR: library directory does not exist. F-Linsey was not properly installed."
exit 1
fi
# Including important library files
source "${FL_LIB_DIR}/errors.sh"
source "${FL_LIB_DIR}/handle_help.sh"
source "${FL_LIB_DIR}/modules.sh"
# Checking if modules directory exist
FL_MODULE_DIR="${FL_THIS_DIR}/modules"
if [ ! -d "${FL_MODULE_DIR}" ]
then
fl1_err_no_modules
Using a function for a trivial piece of code that is only used once
makes the script harder to understand.
Put the body of the function in-line; it's only two lines.
fi
# Parsing command line
# Checking if parameters passed
if [ $# -lt 1 ]
then
fl1_handle_help
You should keep lines shorter than 80 characters for your help text.
fi
# Reacting to command
FL_COMMAND=$1
shift
# Checking if command handler exists
if [ ! -f "${FL_LIB_DIR}/handle_${FL_COMMAND}.sh" ]
then
fl1_err_unknown_command $FL_COMMAND
fi
Ditto.
# Loading command handler file and calling handler
source "${FL_LIB_DIR}/handle_${FL_COMMAND}.sh"
Rather than bash-specific code, use the portable dot command:
. "${FL_LIB_DIR}/handle_${FL_COMMAND}.sh"
fl1_handle_${FL_COMMAND} $*
echo "F_Linsey finished."
Now, which line causes the error?