getfunc() { declare -f "$@" } function func(){ echo "I am a sample function" } funcd="$(getfunc func)" getfunc func # or echo "$funcd"
Output:
func () { echo "I am a sample function" }