I'm fairly new to bash scripting, and wondered what's the simplest way to make bash script functions in a script as the parameter when run via command line?Example usage:./myscript function1./myscript function2Example contents of myscript:echo Example myscriptfunction1() {     echo I am function number 1}function2() {     echo I am function number 2}if [ $# -eq 0 ]; then    echo Specify a function. E.g. function1    exit 1;fiThe script would only execute the specific function when called for on command line otherwise would show some example usage. It would need to be usable by cron and such processes as well as executed by a user.
What's the best way to make a bash function in a script as a parameter when running via command line?
bash;shell script;function
All arguments passed to shell script was stored in $@, you can loop through them:#!/bin/bashecho Example myscriptfunction1() {     echo I am function number 1}function2() {     echo I am function number 2}if [ $# -eq 0 ]; then    echo Specify a function. E.g. function1    exit 1;fifor func do  [ $(type -t -- $func) = function ] && $funcdone[ $(type -t -- $func) = function ] make sure that we only make function call when $func is function.Example:$ ./test.sh function1Example myscriptI am function number 1$ ./test.sh function1 function2Example myscriptI am function number 1I am function number 2