In bash, when I'd like to have a glimpse at what an already defined shell function does, I can:

$ type myFunctionName

For a variable myFunctionName, it provides me with the type of the variable (a function), but also print the source of this shell function on the terminal. Very handy.

When I do the same in zsh, it only gives me the its type, not its shell code.

Is there a way to ask zsh to print to source of a shell function given its name ?


For both zsh and bash (and ksh) you can use typeset -f myFunctionName to get the function definition

% x()
function> {
function> echo x
function> }

% typeset -f x
x () {
        echo x
  • See also which myFunctionName in zsh (where zsh is builtin like in tcsh) May 18 at 11:48
  • 1
    For completeness, in yash, you'd need typeset -pf x May 18 at 11:51
  • I don't understand the function> notation . How do you make this prompt happen ? May 18 at 11:58
  • 1
    The function> prompt automatically appeared for me when I began the function definition x() on the command line. It's zsh's way of telling the user they're in the middle of defining a function. It's the default on my (old) MacOS machine where I tested. May 18 at 13:09
  • @StephenHarris thanks. I had forgotten I had already set an alias x="exa" ... That's the reason I had no such prompt when I hit enter try to do your example with x (). That's excellent, I was always moving to .sh file when the one-liner was becoming a bit too complex but still easy. I'll use this now. May 18 at 14:27

Not the answer you're looking for? Browse other questions tagged or ask your own question.