I use module command to load and unload stuff to my environment, some of the machines I use have proper auto-completion others do not.

I'm wondering if I it possible to know where the completion comes from and install elsewhere.

  • Your question title and description seem unrelated.
    – jordanm
    Oct 31, 2013 at 19:27
  • Why? fell free to edit it
    – RSFalcon7
    Oct 31, 2013 at 19:41

1 Answer 1


You can show completion code for a command using the complete builtin. Here is an example:

$ complete -p ls
complete -F _longopt ls

If you are interested in what the _longopt does, you can use the type builtin:

$ type -a _longopt
_longopt is a function
_longopt () 
    local cur prev words cword split;
    _init_completion -s || return;
    case "${prev,,}" in 
        --help | --usage | --version)
   ----- snip ------

In case of functions you can the solution pointed by HairOfTheDog here:

# Turn on extended shell debugging
shopt -s extdebug

# Dump the function's name, line number and fully qualified source file  
declare -F _longopt

# Turn off extended shell debugging
shopt -u extdebug

Bash does not have a way of determining where environment variables or functions were defined in the initialization process. Otherwise, you can get is running bash with -x.

bash -x -i -l

This will execute an interactive login shell in debug mode, which will show every line executed. If you find the function definition in the output, you can then find the last source or . command that came before it.

  • Thanks! this is useful to determine where the function come from
    – RSFalcon7
    Oct 31, 2013 at 19:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .