Take the 2-minute tour ×
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.

I am currently running 64-bit Debian Wheezy.

I am having some trouble with auto completion for apt-get. I have bash-completion installed.

If I am logged in as root in a shell, I can use auto completion for apt-get (ex: apt-get install wicd[tab][tab]) and it will show me all the packages that match that. But if I try to use auto completion for apt-get in another non-root user (even with sudo) it will not work at all. I can auto complete other things like file names.

Any help?

I do have the following code in my .bashrc and /etc/profile

 if [ -f /etc/bash_completion ]; then
      . /etc/bash_completion
 fi
share|improve this question
1  
First, check whether root and the other users have the same shell. If not, that's the reason for the different behaviour. Otherwise, try this: ‘apt-cache --no-generate pkgnames "wicd"’. Does it work? That's what bash uses to generate the completion of ‘apt-get install wicd[TAB]’. –  angus Jan 12 '12 at 0:10
    
They are both using the same shell, bash. the apt-cache command you gave me does work and shows a list of all the wicd packages. Also, what I found out is when my computer first boots up and I log into the shell for the first time ( I do not have a gui log in), the apt-get autocompletion will work with any account. But if I run my fvwm-crystal window manager with startx, then open a terminal, it will not work again with just my user account. It still works with root in fvwm-crystal. –  Dennis Linuz Jan 12 '12 at 16:54
    
OK, this is what can be happening. /etc/profile and .bash_profile are run on login shells. That is, when you login on the console, or when you run ‘su’. Since in those cases completion works, /etc/profile is working. What's left is ~/.bashrc. Check that the line ‘. /etc/bash_completion’ is really being executed. Put something like ‘echo OK’ before it, open a new terminal, and check it says ‘OK’. –  angus Jan 12 '12 at 20:15
    
did you ever tested ZSH ? –  Efazati May 13 '12 at 9:45

4 Answers 4

Your /etc/bash_completion file must be missing.

sudo apt-get install bash-completion

should solve all your problems.

Given that you already have lines uncommented in /etc/bash.bashrc as Faheem Mitha and others pointed out, it should work now:

# enable bash completion in interactive shells
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

Reason: The bash-completion package now has that file (/etc/bash_completion). It used to be in the bash package, but not any more.

info on package change

share|improve this answer

Try running this:

chsh -s /bin/bash user_name
share|improve this answer

I can't remember if this is necessary, but try uncommenting the corresponding lines from /etc/bash.bashrc if not already uncommented, namely

# enable bash completion in interactive shells
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi
share|improve this answer

As I remember, bash autocompletion for command parammeters is done via the complete command. You should have an apt-get completion script loaded by the root user bashrc (maybe /root/.bashrc), so you need root login to run it. Sudo does not load root login scripts, it just gives you privileges.

Maybe you're missing that autocompletion script for non-root users, so they don't have bash autocompletion configured for apt-get. If that is true, load that functions for users having ALL privileges within the sudoers file.

share|improve this answer

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.