Invoke function whose name is stored in a variable in bash

You should be able to just call the function directly using

$call_func

For everything else check out that answer: https://stackoverflow.com/a/17529221/3236102
It’s not directly what you need, but it shows a lot of different ways of how to call commands / functions.

Letting the user execute any arbitrary code is bad practice though, since it can be quite dangerous. What would be better is to do it like this:

if [ $userinput == "some_command" ];then
    some_command
fi

This way, the user can only execute the commands that you want them to and can even output an error message if the input was incorrect.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)