Ben Kim Ben Kim - 1 year ago 74
Bash Question

Shell Script call a function with a variable?

Hi I'm creating a shell script.

and an example code looks like


echo "It works!"

funcion_name = "test_func"

I want to somehow be able to call test_func() using the variable "function_name"

I know that's possible in php using call_user_func($function_name) or by sying $function_name()

is this also possible in the shell scripting?

Huge appreciation for the help! :)

Answer Source
test_func() {
    echo "It works!"


eval ${function_name}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download