Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have just came across something that is really bothering me. Autocompletion on ubuntu works like a charm but when I login as root, e.g. su I get tab autocompletion only sometimes.

Why does it work like that? Can one change that?

share|improve this question
    
Are you actually logging in as root, or using sudo su? –  Marty Fried Feb 12 '12 at 19:08
    
@MartyFried Yes I am diong sudo su. What is the difference? –  Patryk Feb 12 '12 at 19:19
    
It seems to work for me, can you provide us with a specific instance of when it does not work, something that we can replicate. –  Ubuntu_kwr Feb 12 '12 at 20:20
    
@lordmonkey: Maybe none, I'm not really sure. I think su or sudo su by itself is a little different in some way that I don't remember, so I wanted to make sure that I could check this under the same conditions. It seems like it works, but you said "sometimes", so I can only suggest you double-check and try to make it reproducible, or just make sure there's not something else happening that is fooling you - ie, user error - hey, it happens to everyone! :) –  Marty Fried Feb 12 '12 at 20:48
add comment

4 Answers

up vote 9 down vote accepted

Check your /root/.bashrc file for these lines

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

If they do not exist add them to the end of the file using your favorite text editor.

share|improve this answer
    
Mine .bashrc contained the mentioned lines but they were commented out; uncommented the lines and sourced the new .bashrc ; things look pretty good now . –  Ankit Jul 10 '12 at 2:30
add comment

You haven't mentioned which Ubuntu version you use.

  • Check if you have the bash-completion package installed:

    sudo apt-get install bash-completion
    
  • Mine works if I login using: sudo -i

share|improve this answer
    
What's the point of removing root's .bashrc? –  geirha Jun 27 '12 at 11:09
    
I think it will regenerate the default .bashrc upon next logout/login. Or perhaps it could contain some kind of "deactivation" for autocompletion (don't know if it's possible). I can't remember the actual reason I wrote it down though. –  medigeek Jun 27 '12 at 13:23
1  
No, a new .bashrc will not be created, and /etc/bash_completion will not be sourced, only bash's default completion will be available. –  geirha Jun 27 '12 at 13:35
    
OK, edited and removed. Thank you for your input! Though I wonder if ~/.bashrc can "unsource" a file or if disable-completion is still available: superuser.com/questions/37148/… –  medigeek Jun 28 '12 at 4:34
add comment

For Ubuntu 13.10, check /etc/bash.bashrc for

# 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

They might be commented. Un-commenting them works.

share|improve this answer
add comment

Found that this worked (similar to the answers above but with a twist)

The file that needs to be edited (at least in my case with 12.04) was /root/.bashrc. This makes sense in my case, given that my regular user was autocompleting just fine but my root wasn't.

Anyway in said file I found all the necessary code but it was commented out:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    #. /etc/bash_completion
#fi

Just un-commented it:

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

Saved, and it worked just fine.

Hope this helps someone.

share|improve this answer
add comment

Your Answer

 
discard

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.