Topaz: .bashrc Not Being Sourced

Problem

Shell startup file .bashrc not being sourced specially on Topaz

This is specially a CentOS/Red Hat specific issue as the .bashrc is sourced by the user shell startup.

  • Magnus/Galaxy/Zeus are essentially based on SUSE SLES12 where the default user profile automatically sources this
  • Whereas Topaz, that is Centos 7, does not


To understand the problem 

CentOS specific basically in short

  • ".bash_profile" is sourced for login shell
  • ".bashrc" is sourced for interactive non-login shells.

The dummy default CentOS specific home area, they have a dummy file for .bash_profile and .bashrc. For example:

  • Notice in the dummy default .bashprofile they execute ~/.bashrc
  • Notice in the dummy default .bashrc they source /etc/bashrc
  • So they have to be explicitly sourced in the user version's of .bashprofile and .bashrc which is not needed in SUSE SLES12
Terminal 1: View the .bashrc and .bash_profile files
$ pwd
/etc/skel

$ cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 

$ ls -al
total 36
drwxr-xr-x.   2 root root  4096 Sep 26 14:50 .
drwxr-xr-x. 113 root root 12288 Jan  3 13:24 ..
-rw-r--r--.   1 root root    18 Oct 31  2018 .bash_logout
-rw-r--r--.   1 root root   193 Oct 31  2018 .bash_profile
-rw-r--r--.   1 root root   231 Oct 31  2018 .bashrc
-rw-r--r--    1 root root   334 Oct 30  2018 .emacs
-rw-r--r--    1 root root   658 Oct 31  2018 .zshrc

$ cat .bashrc 
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions

$ cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

root@topaz-1:/etc/skel>cat .bashrc 
# .bashrc

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=

# User specific aliases and functions


Solution

Thus to fix this, do the following assuming you have a default SLES based home area

For ".bashrc" in your home area (ie /home/{username}/.bashrc

  • Add the following lines

    Listing 1: Additional lines for the .bashrc file
    if [ -f /etc/redhat-release ]; then
        if [ -f /etc/bashrc ]; then
    	    . /etc/bashrc
        fi
    fi

Similarly for ".bash_profile" in your home area (ie /home/{username}/.bash_profile

  • Add the following lines

    Listing 2: Additional lines for the .bash_profile file
    if [ -f /etc/redhat-release ]; then
        if [ -f ~/.bashrc ]; then
    	    . ~/.bashrc
        fi
    fi

Filter by label

There are no items with the selected labels at this time.