Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to view the "source" for a ksh function?

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

like image 612
stevec Avatar asked Apr 08 '10 13:04

stevec


1 Answers

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.

like image 199
pra Avatar answered Nov 10 '22 02:11

pra