21

I have setup several functions in my .bashrc file. I would like to just display the actual code of the function and not execute it, to quickly refer to something.

Is there any way, we could see the function definition?

3 Answers 3

25

The declare builtin's -f option does that:

bash-4.2$ declare -f apropos1
apropos1 () 
{ 
    apropos "$@" | grep ' (1.*) '
}

I use type for that purpose, it is shorter to type ;)

bash-4.2$ type apropos1
apropos1 is a function
apropos1 () 
{ 
    apropos "$@" | grep ' (1.*) '
}
3
  • In Ubuntu 18.04, type outputs: <function> is a shell function from <location>, and not the content.
    – Timo
    Apr 7, 2020 at 4:54
  • 1
    @Timo, are you sure that is Bash? Sounds like Zsh behavior.
    – manatwork
    Apr 7, 2020 at 9:03
  • thanks for the hint, here is the solution.
    – Timo
    Apr 8, 2020 at 5:07
7

You can use the type command to do this.

type yourfunc will print the function to STDOUT. As man type says,

The type utility shall indicate how each argument would be interpreted if used as a command name.
5
  • 3
    man type? Shell builtins usually have no man page on my system.
    – manatwork
    Dec 27, 2012 at 8:41
  • I have updated my answer with a link. The system I use is Arch Linux.
    – jasonwryan
    Dec 27, 2012 at 8:55
  • 1
    Thank you. Seems the man-pages package contains much more on Arch.
    – manatwork
    Dec 27, 2012 at 9:05
  • No problem: as it is one of the POSIX man pages, I thought it would be widely distributed...
    – jasonwryan
    Dec 27, 2012 at 9:10
  • 5
    help type shows the Bash-specific information.
    – l0b0
    Dec 27, 2012 at 12:25
0

for builtin commands' info use:

help [-s|-d] COMMAND1 COMMAND2 ....

for example:

help help alias

For info about all of them type, for example:

help -s '' 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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