Larger Script Organization
Source Helper
Choose a Library
Larger scripts often move reusable functions into helper files. A small selector can decide which helper library the entry script loads.
Program
Play the script to choose the helper and see the source plan.
source_helper_plan.sh
#!/usr/bin/env bash
helper=
case "$helper" in
math) helper_file="lib/math.sh"; function_name="add_numbers" ;;
text) helper_file="lib/text.sh"; function_name="trim_line" ;;
esac
echo "source $helper_file -> $function_name"
#!/usr/bin/env bash
helper=
case "$helper" in
math) helper_file="lib/math.sh"; function_name="add_numbers" ;;
text) helper_file="lib/text.sh"; function_name="trim_line" ;;
esac
echo "source $helper_file -> $function_name"
source
`source` loads shell definitions into the current script.
helper file
A helper file groups related reusable functions.
entry script
The entry script chooses what helpers it needs before running the main flow.