Show Shell Function in Ubuntu Terminal

Over the years I’ve moved away from using aliases to defining functions in a .functions file that I source at the time of launching the shell. This works fine, but one feature of alias that I miss is being able to see what a particular function does.

Example:

  • Alias:

    alias tailnet='journalctl -f -u NetworkManager'
    
  • Function:

    tailnet() {
      # Continuous tailing of the network log
      journalctl -f -u NetworkManager
    }
    

In order to see what the alias tailnet does, I can just type alias tailnet and the definition of the alias will be shown. Is there something similar for functions or do I have to open the file where the function is defined?

Asked By: Tex

||

Use declare:

declare -pf tailnet
  • -p tells declare to print the definitions;
  • -f tells declare tailnet is a function.
Answered By: choroba

You can do both (and maybe more) at once with type -a like so:

$ type -a tailnet
tailnet is aliased to `journalctl -f -u NetworkManager'
tailnet is a function
tailnet () 
{ 
    journalctl -f -u NetworkManager
}
Answered By: Raffa
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.