4

I have two systems with debian squeeze installed. On one system when I type:

service <TAB> 

it shows me all available service (from /etc/init.d)

on the other system it shows me all files from the current directory. Does anyone know which setting changes that behaviour ?

UPDATE:

The file /etc/bash_completion.d/service was missing. I copied it from the machine where it is working. If I type complete -p | grep service it shows me:

complete -F _service service

On the machine where it is not working that command shows me nothing. I executed complete -F _service service in the command line, after that, the command service <TAB> shows me:

service -su: completion: function `_service' not found

this function is defined in the service file I recently copied, for some reasons it can't be found ...

  • Do you have /etc/bash_completion.d/service file present? – Janne Pikkarainen Jun 28 '12 at 14:28
  • The file wasn't there, I've added it, but it's still not working. I've seen with complete -p I can display all bindings, on the machine where it is working it shows me a lot of binding, where it's not working it displays nothing. I think it doesn't bind for some reason the files in /etc/bash_completion.d ... – markus Sep 7 '12 at 7:55
17

First of all check if bash-completion is installed run:

 $ dpkg -l bash-completion | tail -1

it should output something like:

ii  bash-completion  1:1.3-1  programmable completion for the bash shell

If output is empty thus install it with:

aptitude install bash-completion

Then check if it is enabled:

 $ grep -A 2 bash_completion ~/.bashrc /etc/bash.bashrc

Should output something like

~/.bashrc:if [ -f /etc/bash_completion ]; then
~/.bashrc:    . /etc/bash_completion
~/.bashrc:fi

If nothing like this or it is commented (has # after ~/.bashrc:) then add/uncomment

if [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
fi

to ~/.bashrc and reread it with

. ~/.bashrc

After that it should work fine.

  • 1
    bash completion works on both machines, but different. if I type service <TAB> it shows me all services on one machine, on the other one the files of the current directory. – markus Jun 28 '12 at 15:01
  • Are versions of bash-completion the same? – rush Jun 28 '12 at 15:03
  • same debian versions, some bash-completion – markus Jun 28 '12 at 15:06
  • one difference is on server 1 I'm directly on the console, an server 2 I'm connected via ssh. – markus Jun 28 '12 at 15:46
  • 2
    Directory completion is NOT bash_completion, which is an ugly hack perpetrated by Debuntu on the readline library (which is what shells use to ...read...lines). bash_completion is NOT enabled on the second box. – adaptr Jul 5 '12 at 8:46
0

I was having the same issue, but "tab" only showed two of the many services. Looking at /usr/share/bash-completion/bash_completion you can see:

_sysvdirs()
{
    sysvdirs=( )
    [[ -d /etc/rc.d/init.d ]] && sysvdirs+=( /etc/rc.d/init.d )
    [[ -d /etc/init.d ]] && sysvdirs+=( /etc/init.d )
    # Slackware uses /etc/rc.d
    [[ -f /etc/slackware-version ]] && sysvdirs=( /etc/rc.d )
}

in my case, /etc/rc.d/init.d existed and had only two services. After removing that dir, everything worked fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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