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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have writen my own initscript /etc/init.d/myscript. I can start and stop my script with the service command

service myscript start
service myscript stop

When I type service <TAB>, bash_completion displays all my initscripts from /etc/init.d/, including myscript. But when I type service myscript <TAB> nothing happens. I would like bash_completion to offer me start, stop as with other initscripts. For example, bash_completion works for service cups <TAB>, but I don't know where this is defined. There is no /usr/share/bash-completion/completions/cups or /etc/bash_completion.d/cups. So where does service get the info from? Where should I add my script info?

share|improve this question
on my system (centos) I have /usr/share/bash-completion/cups from bash-completion rpm. – guido Nov 18 '13 at 23:05
What distribution are you using? Tab completion doesn't work for services on RHEL out of the box. Just tested on a brand new image of RHEL6.3 and CentOS5.4. That is, unless I'm already located in /etc/init.d/. – Jeight Nov 18 '13 at 23:08
@Jeight you need the yum package bash-completion from the EPEL repository – guido Nov 18 '13 at 23:29
I understand that, but not all distros have scripts for services in /etc/bash_completion. Even if there is support, he will need to find the script used for services and edit the case options to include his script in that file. – Jeight Nov 18 '13 at 23:42
Other distos use sybolic links in /etc/bash_completion to direct to the completions script. Usually these are located in /lib/init/. This method is becoming the default way. In which case he will need to create his own upstart-script for auto completion. Let me google for a second to see if someone explained it better. – Jeight Nov 18 '13 at 23:50
up vote 3 down vote accepted

On older versions of bash-completion, like the one available for CentOS on the EPEL repository, there are individual scripts for sysvinit services in /usr/share/bash-completion/. In this case you may want to add additional scripts there based on an example like the cups completion.

On newer systems, like my Fedora 19, bash-completion ships with the _service() and _services() functions in the main /usr/share/bash-completion/bash-completion script, it provides the start and stop actions by default for any installed service. It should work out of the box.

If you also want to support more actions, add an Usage action like this:

    echo $"Usage: $0 {start|stop|status|restart|reload|force-reload}"

The script will parse this string and complete the status, restart, and so on. This assumes that you are using a case statement like this to manage the action argumment:

case $1 in
      echo $"Usage: $0 {start|stop|status}"
share|improve this answer
There it is. I don't have access to a computer right now and was trying to remember off the top of my head. Just to add to that, some Debian based systems have the scripts located in individual locations and are symbolically linked to /etc/bash-completion. – Jeight Nov 19 '13 at 0:07

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.