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.

My terminal autocompletion does not work properly when I use root.

source /etc/bash_completion works if I invoke that manually.

I need to write above code in every new root terminal to be able to use autocompletion.

Any help is appreciated!

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You need to add it to ~/.bashrc, not bash_profile, in this case... but you'll want to only apply it to interactive shells, to avoid taking time whenever you run a script:

case $- in
  *i*) # interactive shell
    source /etc/bash_completion;;
esac

You may need to add to /root/.bashrc for it to work as root... but why are you running a shell as root instead of using sudo for individual commands?

share|improve this answer
    
Testing PS1 has nothing to do with interactive shells, actually. Some distributions ship with files that use that, but it's wrong. Interactive shells have i in their options in $- (even if it wasn't passed explicitly on the command line). –  Gilles Sep 28 '12 at 22:56

Put this line to ~/.bash_profile:

. /etc/bash_completion

share|improve this answer
    
i had no bash profile, so i created it with your entry. this did not work for me. seems like i could not recover the entire /home/ (I accidently deleted it a few days back: unix.stackexchange.com/questions/49080/undo-rm-r-restore-data ). maybe i should just save data and resetup the machine. thanks for your answer thou! –  Wandang Sep 28 '12 at 8:54

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.