Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
rated 0 times [  4] [ 0]  / answers: 1 / hits: 3379  / 1 Year ago, sun, may 21, 2023, 6:28:04

When I log in as root:

ubuntu login: root                                                                                  
Last login: Tue Apr 7 17:31:14 CDT 2020 on ttyS0
Welcome to Ubuntu 19.04 (GNU/Linux 5.0.0-38-generic x86_64)

My /root/.bashrc (and therefore /root/.bash_aliases) are not run. Is this normal? How can I fix this?

Some more info:

# getent passwd| grep root                                     

My /root/.profile is normal:

# cat /root/.profile                                           
# ~/.profile: executed by Bourne-compatible login shells.

if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc

mesg n || true

$BASH is set correctly:

# echo $BASH                                                   

And /root/.bashrc is also normal. Here's a snippet:

if [ -f ~/.bash_aliases ]; then                                                 
. ~/.bash_aliases

If I do ". ~/.bashrc" from the command line, it works as expected.

More From » root


If either ~/.bash_profile or ~/.bash_login exists, bash will run that instead of ~/.profile. Some software installers will helpfully add their setup steps to (usually) ~/.bash_profile, so even if you delete it (and merge its contents into ~/.profile), it might get recreated later.

Ideally, I'd recommend moving all the bash-specific things (i.e. sourcing ~/.bashrc) into ~/.bash_profile, have it also source the generic ~/.profile, leaving just the mesg in the generic ~/.profile (so it'll work if you ever start in a different shell)

So here's what I'd put in ~/.profile:

# cat /root/.profile                                           
# ~/.profile: executed by Bourne-compatible login shells.

mesg n || true

And ~/.bash_profile (note that it doesn't have to test $BASH 'cause it's already in a bash-specific file):

# ~/.bash_profile: executed by bash login shells.

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

# If the generic profile exists, source that as well.
if [ -f ~/.profile ]; then
. ~/. profile

[#3899] Tuesday, May 23, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 169
Total Questions: 105
Total Answers: 141

Location: Sao Tome and Principe
Member since Wed, Dec 29, 2021
2 Years ago