Problem:

On my Ubuntu 15.10 laptop I found TAB key completion was not working in the bash shell / terminal.

Solution:

I started by checking the basics;

  • Running echo $SHELL confirmed I was indeed using a bash shell.

Ubuntu - Shell TAB key completion not working

  • Running dpkg -s bash-completion confirmed bash-completion package was installed.

Ubuntu - Shell TAB key completion not working

  • Next I took a look at the /etc/bash.bashrc file and I found the section to “enable bash completion in interactive shells” had been commented out for some reason. It is not something I would have knowingly done, so the reason why the section was commented out is a bit of a mystery. If you have any ideas, please comment.
  • I changed the section from;
# enable bash completion in interactive shells
#if ! shopt -oq posix; then
#  if [ -f /usr/share/bash-completion/bash_completion ]; then
#    . /usr/share/bash-completion/bash_completion
#  elif [ -f /etc/bash_completion ]; then
#    . /etc/bash_completion
#  fi
#fi
  • To;
# enable bash completion in interactive shells
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi
  • I saved the /etc/bash.bashrc file
  • Closed my current bash shells
  • Opened a new one and tab completion was working fine again.

References:

http://askubuntu.com/questions/33440/tab-completion-doesnt-work-for-commands