Hello.

Is there a way in bash to call a function by it's name?
For example, I have:

MODULE_NAME='test'
FUNCTION_NAME='execute_run'

How do I call the function with name test_execute_run? I need this to solve the problem of modularizing my bash script.

Thank you.

Doesn't this work?

cmd="${MODULE_NAME}_${FUNCTION_NAME}"
$cmd

What about?

eval
eval [arguments]

The arguments are concatenated together into a single command, which is then read and executed, and its exit status returned as the exit status of eval. If there are no arguments or only empty arguments, the return status is zero.

Voila!

Thanks, it should. Using eval also should work as I now know ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.