Bash Completion Doesn't Work In Root User

14,792

Solution 1

Bash completion can be enabled in the file .bashrc as explained in this Q&A. In your case it seems to be correct in your user's .bashrc, but not in your root's .bashrc. The latter file is located in /root/.bashrc. Open this file with your favorite text editor as root (e.g. by running sudo gedit /root/.bashrc) and remove the # in the beginning of the last three lines:

You have to change the lines 98-100 from

#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi

...to:

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

Then close your terminals and reopen them.

Solution 2

I successfully enabled "bash completion" in Ubuntu 12.04 LTS by editing the file "bash.bash.rc" in "etc".

I just removed the "#" in lines 32-34 and bash completion for "sudo" works fine now.

Share:
14,792

Related videos on Youtube

T0M XeOn LuCiFeR
Author by

T0M XeOn LuCiFeR

Updated on September 18, 2022

Comments

  • T0M XeOn LuCiFeR
    T0M XeOn LuCiFeR almost 2 years

    I'm on 12.04 and I'm trying to find a way to enable Bash completion in root user.

    Any ideas on how to do that?

    • lumbric
      lumbric about 12 years
      Possible duplicate? askubuntu.com/questions/33440/…
    • harisibrahimkv
      harisibrahimkv about 12 years
      While trying to type what, is your bash completion not working? Or is it not working at all?
    • T0M XeOn LuCiFeR
      T0M XeOn LuCiFeR about 12 years
      It's Not Working While Trying To Type In ROOT, In Ordinary users It Works Just Fine, For Example : root# apt-get install gua[tab][tab] it Must Show Sth Like Guake, But It Wont, Also For Other Things, While It's Showing The Same Thing While I'm Using An Ordinary User, And Using An Extra "Sudo" Before That Command...
    • T0M XeOn LuCiFeR
      T0M XeOn LuCiFeR about 12 years
      @lumbric : No, That's Not My Answer...;)
    • lumbric
      lumbric about 12 years
      @T0MXeOnLuCiFeR can you add the output of sudo cat /root/.bashrc?
    • Bruno Pereira
      Bruno Pereira about 12 years
      @T0MXeOnLuCiFeR Do you mind not writing "Like This Phrase?", makes things harder to read and makes not sense at all to use.
    • T0M XeOn LuCiFeR
      T0M XeOn LuCiFeR about 12 years
      @lumbric Here's The Output [ I KNOW IT's not in C language, So....] : codepad.org/cP1h0Ae4
    • lumbric
      lumbric about 12 years
      @T0MXeOnLuCiFeR Well... finally it is a duplicate of the suggested question, but a bit more tricky maybe... :) I added detailed instructions as answer.
    • SergioAraujo
      SergioAraujo about 3 years
      In my case (void linux) the root user uses /bin/sh, as soon as I call bash the completion starts working.
  • T0M XeOn LuCiFeR
    T0M XeOn LuCiFeR about 12 years
    tnx, i'm still having problem, see i mean sub commands like when u have typed apt-get now you r going to type "install" u type the first 3 words then you hit tab in normal user it works in root user it doesn't.... what should i do right now...?
  • T0M XeOn LuCiFeR
    T0M XeOn LuCiFeR about 12 years
    I DID, what u told me.... yet it's not working, do you have any other idea?
  • lumbric
    lumbric about 12 years
    @T0MXeOnLuCiFeR I'm quite sure that this is the source of your problem. Did you cat again to see if you actually changed the file as I suggested? Did you close and reopen all terminals? If not, try to run . /etc/bash_completion manually (note that there is a .!).
  • T0M XeOn LuCiFeR
    T0M XeOn LuCiFeR about 12 years
    Yes Man I Did It ... Tnx Anyway It Got Better, But Not What I Thought...I Check For More Details.