3

I have a default Debian 8.1 installation. I do

su
man apt<TAB>

but get nothing. I do see the manual when I write man apt-get in both modes: as user mas and as root. However, tab completion works in the user mode only.

How can I enable table completion after man in root? Why is this disabled by default?

  • If you do su - instead of su, does completion work? – Mark Plotnick Jul 30 '15 at 22:23
7

Running su invokes bash in non-login mode. Bash then reads .bashrc to configure its environment.

Runing su - invokes bash as a login shell. In this mode /etc/profile is executed if it exists. Bash also searches for ~/.bash_profile, ~/.bash_login and ~/.profile executing the first file it finds. Although not documented, it appears to execute ~/.bashrc when none of these exist.

If you get different behavior, it is likely that you are using different files to initialize bash depending on how it is invoked.

I tested which file was invoked by adding lines like echo .bashrc to then end of the existing files. This will display which configurations get invoked.

There is more detail on this behavior in the INVOCATION section of the bash man page.

Tab completion is available in bash but not in sh. root normally has sh as its shell as bash may not be available. Users typically have bash as their shell.

Try running bash as root before trying tab-completion. This should enable tab completion.

  • 2
    root's shell is bash, in Debian 8. And completion does work if you su -, as Mark Plotnick suggested. – Paulo Almeida Jul 30 '15 at 23:57
  • 1
    This doesn't solve the problem and is wrong in several points. On a default Debian installation, root's shell is bash (I think that's been the case in all Debian releases). .bashrc is not read by a login shell (except for non-interactive login shells invoked by rshd or sshd, but then .profile and its cousins are not read). – Gilles 'SO- stop being evil' Jul 31 '15 at 7:19
1

Bash has two completion engines: a simple one that mostly only does completion of commands in command position and file names in argument position, and a fancy one that completes arguments based on the command. To get man page completion, you need the fancy one.

When you start bash, only the simple completion engine is enabled. To get the fancy engine, you need to source /etc/bash_completion. This changes the historical behavior and adds to the startup time, which may be why this isn't the bash default.

In Debian, the instruction to read /etc/bash_completion is present in the default .bashrc for new accounts, but not in the system configuration file /etc/bash.bashrc. It isn't put in the system configuration file because that would make it impossible for users to opt out of it. If you want the fancy completion system in shells running as root, you need to add this line to /root/.bashrc:

. /etc/bash_completion

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.