I've a few special aliases and such set up on a few servers (CentOS 7, bash shell).

Some of them are server specific (ex: what IP point to the internet, hostname of the server, etc), while others are relevant to all of them (command aliases and such).

I've set each server's unique aliases in the ~/.bash_profile file, which sources another file, spread via Git, with all the non-unique environment variables. That way, whenever I add an alias or variable I'd like all servers to add, I add it to the file and push it via Git.

However, I've come to understand that on some (seemingly rare) occasions, the non-unique aliases and variables are only available after sourcing ~/.bash_profile manually after logging in. Most of the time it works okay as is - I log in, and everything is set, while on other times another source is required.

I've tried sourcing the non-uniques file from different locations - using a script from /etc/profile.d/, using /etc/bashrc, /etc/profile, and ~/.bash_rc, which result in a loop which hangs login.

The bash_profile looks something like this:

# .bash_profile
source "/etc/non_uniques_file"

#Unique to this server
alias servername=[name of server]...

And the non-uniques file looks something like this:

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

# User specific environment and startup programs
export PATH
export HISTTIMEFORMAT="%d/%m/%y %T "
export HISTSIZE=2000
export HISTFILESIZE=20000...

My question is - where would be the correct place to source the uniques file from, to have it set system-wide and under all circumstances?

What could be the reason these variables are set in some logins, but not on others, despite the same login method?


2 Answers 2


Private vs global

Any .profile or .rc file(s) like .bashrc, etc. that are stored within the home directory of any registered user belong explicitly to that user.

That means they are not good candidates for sourcing by other users. (ie global).


These are usually the fall-back files. Loaded before any user login, so they function as basic default fall-backs for new users etc.

The location of these can actually be different across different distributions. Locations like /etc/default and similar are good places to start looking.

Due to the free and open source nature of Linux, you should ceck the documentation for more accurate info concerning your distroes.


If you are already logged in before you update a profile or the file that is sourced it will not source it again. You should take a look at the INVOCATION section in the bash manual (man bash) it explains which files are read under various scenarios (Interactive shell, Login shell etc.).

You are also using alias in an unusual manner, I think you should forget alias and just set variables and export them.

I think there are two options:

  1. Don't source anything and just put the two files you want to run in /etc/profile.d I would name them something like, appname_global_vars & appname_node_vars

  2. Put them anywhere other than /etc/profile.d that is readable (You already have /home/bin so why not in there?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .