I always had confusion about login vs non-login shell and today decided to clear this up. Here is what I have understood. Please refer to the following site for more explanation.
Reference: http://www.linuxfromscratch.org/blfs/view/cvs/postlfs/profile.html
When a user starts The shell program /bin/bash
(hereafter referred to as just “the shell”), shell uses a sequence of startup files to create an environment for the user. This includes PATH, PS1, HOME etc. Each file has a specific use and may affect login and interactive environments differently.
First Some definitions:
Login Shell:
A login shell is one whose first character of argument zero is a -, or one started with the –login option. It starts after a successful login using /bin/login and by reading the /etc/passwd file.
Interactive Shell:
An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals, or one started with the -i option.
Three types of shell sessions:
1. interactive login shell:
Following files are read in the specified sequence to establish user environment.
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
When a login shell exits, to cleanup, following file is used:
~/.bash_logout
2. Interactive non-login shell:
Normally started at the command-line using $
/bin/bash) or by the /bin/su command.
This copies the parent environment and then reads the following files, in the specified order, for additional startup configuration instructions:
/etc/bash.bashrc
~/.bashrc
3. Non-Interactive Shell:
A non-interactive shell is usually present when a shell script is running. It is non-interactive because it is processing a script and not waiting for user input between commands. For these shell invocations, only the environment inherited from the parent shell is used.
Summary:
1. In a Interactive non-login shell, parent environment is used and few settings which are specified in “/etc/bash.bashrc and ~/.bashrc” are updated.
2. Whereas, in an interactive login shell, environment is not inherited from parent and is created from scratch.