How to display bash function definition (source code)

I absolutely love bash as glueing programming on my development machine. Shell aliases are one-liners, but bash custom functions offer much more flexibility. I define many functions in ~/.bash_profile or ~/.bashrc. Sometimes I just need to see what function named push_to_prod_project_a() does? How can I see the bash function definition (actual source code at the CLI without opening the ~/.bashrc)?

Yes, bash can display function definition or code. You can use the type or declare keywords.

Displaying bash function definition (source code) using type

  1. Open the terminal application on your Linux, Unix or macOS
  2. For remote system log into it using the ssh:
    ssh user@remote-system-ip
  3. Then run the following command to see function definition push_to_prod_project_a() function:
    type push_to_prod_project_a
  4. Another option is the declare command. It restrict action or display to function names and definitions when you pass the -f followed by the function name you wish to display on screen. For example:
    declare -f function_name

Check my guide for more info: