Bash auto-completion doesn't work as toor user

Hello,


My /etc/passwd is as follows:

Code:
root:*:0:0:Charlie &:/root:/bin/csh
toor:*:0:0:Bourne-again Superuser:/root:/usr/local/bin/bash
I noticed that bash auto-completion doesn't work when logging in as the toor user.

However, if I start a new bash sub-process after logging in as either root or toor, auto-completion works as expected.

Why is that?
 
Yes, it does have a .bashrc (but no .bash_profile).

As both root and toor share the same home directory, I was under the impression that it should be used when logging in as toor.

Code:
[root@freebsd ~]# cat /root/.bashrc
[[ $PS1 && -f /usr/local/share/bash-completion/bash_completion.sh ]] && \
        source /usr/local/share/bash-completion/bash_completion.sh

HISTSIZE=-1
HISTFILESIZE=-1
HISTCONTROL=ignoredups

EDITOR=vim
 
Code:
       When bash is invoked as an interactive login shell, or as a non-
       interactive shell with the --login option, it first reads and executes
       commands from the file /usr/local/etc/profile, if that file exists.
       After reading that file, it looks for ~/.bash_profile, ~/.bash_login,
       and ~/.profile, in that order, and reads and executes commands from the
       first one that exists and is readable.  The --noprofile option may be
       used when the shell is started to inhibit this behavior.

Rename your ~/.bashrc to ~/.bash_profile.

~/.bashrc is loaded when it's an interactive non-login shell. I.e. when you start bash(1) from the command line.
Code:
       When an interactive shell that is not a login shell is started, bash
       reads and executes commands from ~/.bashrc, if that file exists.  This
       may be inhibited by using the --norc option.  The --rcfile file option
       will force bash to read and execute commands from file instead of
       ~/.bashrc.
 
Code:
       When bash is invoked as an interactive login shell, or as a non-
       interactive shell with the --login option, it first reads and executes
       commands from the file /usr/local/etc/profile, if that file exists.
       After reading that file, it looks for ~/.bash_profile, ~/.bash_login,
       and ~/.profile, in that order, and reads and executes commands from the
       first one that exists and is readable.  The --noprofile option may be
       used when the shell is started to inhibit this behavior.

Rename your ~/.bashrc to ~/.bash_profile.

~/.bashrc is loaded when it's an interactive non-login shell. I.e. when you start bash(1) from the command line.
Code:
       When an interactive shell that is not a login shell is started, bash
       reads and executes commands from ~/.bashrc, if that file exists.  This
       may be inhibited by using the --norc option.  The --rcfile file option
       will force bash to read and execute commands from file instead of
       ~/.bashrc.

Thanks. That did the trick.

Is there a common config file that is parsed under both circumstances (bash being started either during login or invoked from another shell)?

Or will I have to maintain both .bashrc and .bash_profile, if I want identical behaviour in both cases?

I have now created a hard-link, but am wondering whether there is a more elegant solution.
 
You often see this in .bash_profile:
Code:
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

That said, why would you want to load completions in a non-interactive shell?
 
Back
Top