I know I can do this:
function foo() { echo "foo"; }; export -f foo
But can I do this without repeating the function name?
I know I can do this:
function foo() { echo "foo"; }; export -f foo
But can I do this without repeating the function name?
set -a # or: set -o allexport
# will be exported:
foo () {
echo foo
}
set +a # or: set +o allexport
# will not be exported:
bar () {
echo bar
}
Setting the allexport shell option in bash will export all functions that you define while the option is set. You could set this option for the section of the file that needs it, then unset it.
Note that this also affects variables that are defined (they are automatically turned into environment variables), but not variables inside function definitions.