# Bash auto-completion doesn't work as toor user



## freebsd-fan (Oct 14, 2022)

Hello,


My /etc/passwd is as follows:


```
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?


----------



## SirDice (Oct 14, 2022)

Does the toor account have a ~/.bashrc or ~/.bash_profile?


----------



## freebsd-fan (Oct 14, 2022)

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.


```
[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
```


----------



## SirDice (Oct 14, 2022)

```
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.

```
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.
```


----------



## freebsd-fan (Oct 14, 2022)

SirDice said:


> ```
> 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.
> ...



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.


----------



## SirDice (Oct 14, 2022)

You often see this in .bash_profile:

```
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
```

That said, why would you want to load completions in a _non-interactive_ shell?


----------

