Skip to content

Instantly share code, notes, and snippets.

@ibnishak
Created September 13, 2021 11:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ibnishak/bcedc99419edf02e9e0b31e60fd6744d to your computer and use it in GitHub Desktop.
Save ibnishak/bcedc99419edf02e9e0b31e60fd6744d to your computer and use it in GitHub Desktop.
Access functions declared in script from commandline
# Suppose you have a script named "myscript" with a function - conquerworld
# You can access those functions from terminal as
# myscript conquerworld <rest of args>
# or
# myscript conquer world <rest of args>
if [ "$1" = "--help" ]; then
helpmenu
exit 0
elif declare -f "$1" > /dev/null; then
"$@"
elif declare -f "$1$2" > /dev/null; then
"$1$2" "${@:3}"
else
echo "'$1' is not a known command" >&2
helpmenu
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment