-1

When I log in as root:

ubuntu login: root                                                                                  
Password:                                                                                               
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                                     
root:x:0:0:root:/root:/bin/bash

My /root/.profile is normal:

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

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

mesg n || true                                                                  

$BASH is set correctly:

# echo $BASH                                                   
/bin/bash

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

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

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

6
  • 3
    Yes, it is. /root/.bash_aliases are run instead, and there is no need to fix it. – mikewhatever Apr 7 '20 at 23:43
  • 1
    Um, ~ is /root when I log in as root, so ~/.bash_aliases is the same thing as /root/.bash_aliases. So on my system, when I log in as root, /root/.bash_aliases is not run. – lord_nimon Apr 8 '20 at 1:52
  • @lord_nimon please modify your question to include the exact path (without the ~ variable) in order to avoid misunderstandings that probably led to the down-votes. – Bruni Apr 8 '20 at 7:13
  • I've updated it as requested, but I don't understand how anyone could be confused. ~ has always been the home directory of whatever your login is. And if you look at the .bash_xxx scripts in /root, they all use ~ and not /root. – lord_nimon Apr 8 '20 at 18:21
  • 1
    Do you have either a /root/.bash_profile or a /root/.bash_login file? If either of those exist, it'll be run instead of /root/.profile, – Gordon Davisson Apr 8 '20 at 18:32
3

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
fi

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

Hy, if you try

getent passwd| grep root

the return of this command is similar to this ?

root:x:0:0:root:/root:/bin/bash

maybee you have different shell than /bin/bash

you can also take a look of your root profile

cat ~/.profile

you need to have :

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

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

mesg n || true

regards

1
  • I have all that. Everything looks right. I've updated the question with this info. – lord_nimon Apr 8 '20 at 18:19

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.