bash - How do I list the functions defined in my shell?


Translate

I can type alias to show a list of all the aliases.

But for functions, all I can do is grep my .bash_profile.

That only gets the ones in that file, not those defined in subsidiary files or dynamically.

Is there a more convenient way to find out what functions are currently defined?


All Answers
  • Translate

    declare -F

    Function names and definitions may be listed with the -f option to the declare builtin command (see Bash Builtins). The -F option to declare will list the function names only (and optionally the source file and line number).

    Bash Reference Manual


  • Translate

    Assuming bash shell:

    typeset -f
    

    will list the functions.

    typeset -F
    

    will list just the function names.


  • Translate
    declare -F
    

    will give you the names of all functions

    type function_name
    

    will give you the source for a particular function


  • Translate

    declare -F actually prints declare commands and not only function names:

    $ declare -F
    declare -f function1
    declare -f function2
    

    You can use compgen -A function to print only function names:

    $ compgen -A function
    function1
    function2
    

  • Translate

    typeset is obsolete, please use:

    declare -f
    

    or

    declare -f function_name
    

    or

    type function_name
    

  • Translate
    set | grep " ()"
    

    In place of grep you can also use fgrep or hgrep (hgrep is my personal favorite, it's grep but it hi-lites the 'grep-ped' result.

    hgrep can be found here: ACME Labs hgrep