Larger Script Organization
Main Dispatch
Route a Command
A larger script can keep argument routing separate from the functions that do real work. The dispatch table maps a command to a handler.
Program
Play the script to choose the command and see the selected handler.
main_dispatch_plan.sh
#!/usr/bin/env bash
command=
case "$command" in
build) handler="run_build" ;;
clean) handler="run_clean" ;;
esac
echo "$command -> $handler"
#!/usr/bin/env bash
command=
case "$command" in
build) handler="run_build" ;;
clean) handler="run_clean" ;;
esac
echo "$command -> $handler"
dispatch
Dispatch selects the handler for a named command.
handler
A handler function contains the command-specific work.
main function
A main function can parse, dispatch, and report without mixing every detail together.