Hi,
It seems with bash 4.3.30(1)-release (and probably others) that embedded functions are output with a leading 'function ' keyword when using declare -f / typeset -f. This is different to all other shells that support declare / typeset that I've tested (pdksh, mksh, Mac OS X ksh, which I think is AT&T)
Produces this with typeset -f
helloworld ()
{
echo hello;
function embed ()
{
echo by
}
}
whereas pdksh, for instance, produces:-
helloworld() {
echo hello
embed() {
echo by
}
}
The other ksh88 derivatives are very similar apart from indentation, it seems.
Is this by design? It's a little annoying for my situation*, as it makes it impossible to consume the output from declare -f / typeset -f with another POSIX shell (I am cognisant that of course ther emight be other bash syntax in there, eg arrays, but I can code to make sure none is present). If there's no workaround in bash itself, does anyone know a regex I could apply safely to the output to remove the nested 'function ' statements. One that is heredoc aware? Or am I going to have to write a parser (:-( ? Or is there another way?
Many thanks
Raph
PS First posting of any note, so apologies in advance for any breach of etiquette.
* PPS I have a couple of use cases, one of which is running a portion of code under sudo from a generated script in a chroot where bash has not yet been installed. Another is allowing user code additions. Such is life.