Understanding the distinction between your shell types, profile files and shell rc files is important because when you apply modifications to your system you need to know where to set variables in order to make sure that they can be initialized as expected.
Let’s give a quick answer for this topic which covers the exact difference between the two shells.
When you login your system and see the command line prompt, it’s a login shell, and it executes these files in order:
A non-login shell will only execute the two files in order:
So what’s a non-login shell?
When issuing this command:
$ ssh firstname.lastname@example.org ‘uptime’
you will gain a non-login shell at the remote side howto.admon.org. when you type bash after login, your new shell is also a non-login shell.
Now, you may have a clear answer to a common system administration question: How can I properly apply a new system variable like JAVA_HOME?
It’s better to set it in /etc/bashrc other than /etc/profile. Addtionally, there’re better choice. If you prefer to make your system clean and tidy, it’s suggested to create single config files in /etc/profile.d, the point is all these file would be initialized by both login shell and non-login shell:
$ grep profile /etc/profile /etc/bashrc
/etc/profile:for i in /etc/profile.d/*.sh ; do
/etc/bashrc:# Environment stuff goes in /etc/profile
/etc/bashrc: for i in /etc/profile.d/*.sh; do
NOTE: The suffix of the file name should be “.sh”, e.g. /etc/profile.d/java.sh