以root身份登录时,自动完成function不起作用
我刚刚遇到了一些让我困扰的事情。 ubuntu上的自动完成就像一个魅力,但是当我以root用户身份登录时,例如su
我有时只能获得tab
自动完成function。
它为什么这样工作? 可以改变吗?
检查/root/.bashrc
文件中的这些行
if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi
如果它们不存在,请使用您喜欢的文本编辑器将它们添加到文件的末尾。
您没有提到您使用的是哪个Ubuntu版本。
-
检查是否安装了
bash-completion
软件包:sudo apt-get install bash-completion
-
如果我使用以下
sudo -i
我的工作正常:sudo -i
对于Ubuntu 13.10,请检查/etc/bash.bashrc
# 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
他们可能会被评论。 取消评论他们的作品。
发现这有效(类似于上面的答案,但有一个扭曲)
需要编辑的文件(至少在我的情况下是12.04)是/root/.bashrc。 这在我的情况下是有道理的,因为我的常规用户自动完成正常但我的根本没有。
无论如何在我的文件中我找到了所有必要的代码,但它被注释掉了:
# 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
只是没有评论它:
# 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
保存,它工作得很好。
希望这有助于某人。
在Linux Mint 18(基于Xenial)中,您必须编辑bashrc:
sudo nano /etc/bash.bashrc
并注释掉(删除每行前面的#
)本节:
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
就这样。