Created
September 13, 2021 11:00
-
-
Save ibnishak/bcedc99419edf02e9e0b31e60fd6744d to your computer and use it in GitHub Desktop.
Access functions declared in script from commandline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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