Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question
Your question title and description seem unrelated. –  jordanm Oct 31 '13 at 19:27
Why? fell free to edit it –  RSFalcon7 Oct 31 '13 at 19:41

1 Answer 1

up vote 5 down vote accepted

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.

share|improve this answer
Thanks! this is useful to determine where the function come from –  RSFalcon7 Oct 31 '13 at 19:37

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.