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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityThe 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.*) '
}
type
outputs: <function> is a shell function from <location>
, and not the content.
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.
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 ''