How to get functions propagated to subshell?

You can propagate functions from bash to bash subshells:

function greet1 {
  echo "moin, $1"
}
typeset -fx greet1

greet2() {
  echo "servus, $1"
}
typeset -fx greet2

echo "greet1 bob; greet2 alice" | bash

Output:

moin, bob
servus, alice

Also, see https://docstore.mik.ua/orelly/unix3/upt/ch29_13.htm


Functions are naturally propagated to subshells:

greet () {
  echo "hello, $1"
}
( echo "this is a subshell"; greet bob )

But they are not and cannot be propagated to independent shell processes that you start by invoking the shell under its name.

Bash has an extension to pass functions through the environment, but there's no such thing in other shells. While you can emulate the feature, it requires running code in the nested shell anyway. You might as well source your function definitions in the nested shell.