views:

139

answers:

2

Our ksh environment defines several functions. The names of these functions can be listed using then typeset -f ksh command (or the functions alias). Is it possible to see the definition (ie source code) for these functions?

This seems like an obvious question, but I've tried all manner of parameters to typeset -f with no luck.

As an example (on Linux):

$ foo()
> {
>  echo foo
> }
$ foo
foo
$ typeset -f foo
foo
$

For some (but not all) other functions defined by default in the environment, typeset -f does show the source.

Update 1: This is happening with Linux kernel 2.4.21-32

Update 2: Update 2: Ctrl-V gives "Version M 1993-12-28 n+" - seems like this is quite an old version so might not have the fixes mentionned by Gilles below

Thanks, Steve

A: 

To see the source of a given function, use typeset -f <function-name>, for example:

$ foo
foo
$ typeset -f foo
function foo
{
    echo foo
}

You can also use a bare typeset -f to see all functions and their source.

pra
Thanks - I hadn't realised that `functions` was just an alias to `typeset -f` - I've updated the question above.
stevec
pra
2.4.21-32 (I've also updated the original question above)
stevec
A: 

The question doesn't mention the version of ksh but suggests an older version which may have a bug or limitation. Here are relevant extracts from the ksh93 changelog:

08-01-31 --- Release ksh93s+ ---
07-11-01 A bug in which typeset -f fun did not display the function definition when invoked in a subshell has been fixed.

03-03-18 --- Release ksh93o ---
03-02-28 All function definitions can be displayed with typeset -f not just those stored in the history file. In addition, typeset +f displays the function name followed by a comment containing the line number and the path name for the file that defined this function.

Gilles
Thanks - edited question. Steve
stevec