I have a bash script of the form:
cat << EOF > stackoverflow_source.sh
#!/bin/bash
function f1 () {
echo This is the first function.
}
function f2 () {
echo This is the second function.
}
EOF
and its GUI with gtkdialog:
$ cat << EOF > stackoverflow_gui.sh
#! /bin/bash
source stackoverflow_source.sh
export MAIN_DIALOG='
<window window_position="1" title="StackOverflow Question">
<hbox>
<button>
<label>Function One</label>
<action>f1</action>
</button>
<button>
<label>Function Two</label>
<action>f2</action>
</button>
</hbox>
</window>'
gtkdialog --program=MAIN_DIALOG
EOF
So after running:
$ source stackoverflow_source.sh
I get:
$ f1
This is the first function.
but when I click the corresponding button in the gui (even after sourcing the script) I get
sh: f1: command not found
When I export the functions with
$ export -f f1 && export -f f2
they do work in the gui (sh stackoverflow_gui and clicking their buttons, echos the text).
Is there a way to export every function in my stackoverflow_source.sh script? (In my real source script I have hundreds of functions and I do not want to do it one by one).
Alternatively, is there a better way to do what I want?