I need to define a Bash function in the Bash environment from a C/C++ program. Before the shellshock bug, I could define a function in this way:
my_func='() { echo "This is my function";}'
Or equivalent from a C program:
setenv("my_func", "() { echo \"This is my function\";}", 1);
Or
putenv("my_func=() { echo \"This is my function\";}");
But using a Bash version with shellshock fixed, I can't manage on how to define my functions in the environment.
The strange thing is, if I run env
, I can see my function defined in the environment, but if I call it, Bash says that it doesn't exist.
Thanks in advance
declare
orexport
... – Emaliaexport -f
, but I need to do it programatically from a C program. I don't know how to export a function definition from a C program to the environment withoutputenv
orsetenv
. Thanks for your answer – Gortonbash
, like plain-old-shell, dash, ksh, zsh and so on. Therefore, you probably want source them as @starrify already told you... – Emaliasystem()
or some other way? – Burma