Issue
case ${1} in
"pkey") pkey ;;
"abserver") abserver ;;
"exitmenu") exitmenu ;;
"i3-binds") i3-binds ;;
esac
I have this code to call a function in a script based on $1 (passed as an argument to script). Is there a way to simply call the function in question via $1 and remove the need for case statement?
Solution
I would use this to validate the parameter:
case $1 in
pkey|abserver|exitmenu|i3-binds) "$@" ;;
*) echo "Unknown function: $1" >&2 ;;
esac
I used "$@"
to also pass the other parameters as arguments to the function.
Answered By - glenn jackman Answer Checked By - Timothy Miller (WPSolving Admin)