How do I create a function named from the contents a variable? I want to write a template script that defines a function named after the script’s own file name. Something like this (which of course doesn’t work):
#!/bin/bash
bname="$(basename $0)" # filename of the script itself
someprefix_${bname}() { # function's name created from $bname variable
echo test
}
So if the script’s filename is foo.sh, then it should define a function named someprefix_foo that will echo “test”.
You can use
eval:Bash even allows
"."s in function names 🙂