tab completion for service command on debian
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.
Related videos on Youtube

markus
Updated on September 18, 2022Comments
-
markus about 1 month
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 commandservice <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 ...
-
Janne Pikkarainen over 10 yearsDo you have
/etc/bash_completion.d/service
file present? -
markus about 10 yearsThe 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 over 10 yearsbash 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.
-
rush over 10 yearsAre versions of
bash-completion
the same? -
markus over 10 yearssame debian versions, some bash-completion
-
markus over 10 yearsone difference is on server 1 I'm directly on the console, an server 2 I'm connected via ssh.
-
adaptr over 10 yearsDirectory 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.