Whenever you operate a Linux system behind the scenes, you might be encountering the interactive login or non-login shell.
The most important thing is that you are not aware of them, so you don’t know when they are switching, and this lack of knowledge makes it hard for young Linux users to understand the concept of Linux profiles like “/etc/profile”, “~/.bash_profile”, “~/.profile”, “~/.bashrc”, etc.
Today, all doubts related to interactive vs. non-interactive and login vs. non-login shells will be cleared.
Interactive vs Non-Interactive Shell
To understand the difference between them, you need to understand that in both cases, a shell is being used, so the shell is in the center for both of them.
Now, an “interactive shell” is when the user (referring to you) directly interacts with the shell by typing the commands in the terminal, where the shell will read your commands and return you the processed output.
Whereas, a “non-interactive shell” is a method of working with shell without user interaction, such as a shell script.
Note that every shell script uses the non-interactive shell approach and does not load or execute any startup file; instead, it inherits the environment variables from the shell that created it.
That’s all you need to know about them; let’s move on to the next.
Also Read: What is Bash Shell in Linux?
Login vs Non-Login Shell
An interactive shell can either be a login shell or a non-login shell.
The “interactive login shell” is the first process that initiates under the user ID after system boot, or using the “-login” flag. Even if you log into a remote system using SSH, it will be considered an interactive login shell.
Apart from that, you must also know that interactive login-shell will load some configuration files (or profiles), like “~/.bash_profile,” into your current shell environment.
This file will be sourced (read and executed) in your current shell environment only once, when you boot your system; after that, you most probably interact with an interactive non-login shell.
The “interactive non-login shell” is when you initiate multiple shells in your current environment by executing bash in your terminal or opening a new terminal tab. So you are able to get any number of them after you log in to the system.
This event will not load the profiles like “~/.bash_profile“, but instead source (read and execute) the “~/.bashrc” file.
So, the major difference between both of them is that the interactive login shell will initiate on system boot and load the “~/.bash_profile” only once.
After that, you only interact with the interactive non-login shell, and it will not load the “~/.bash_profile“; instead, it will load the “~/.bashrc“, a number of times depending on the number of times you initiate a new interactive non-login shell.
One more thing you must know is that many distributions use “~/.profile” instead of the “~/.bash_profile” file.
So, when an interactive login shell is initiated, it will first look for the “~/.bash_profile” file; if the file does not exist, it will look for the “~/.profile” file; if that file also does not exist, it will look for the “~/.bash_login” file.
Note that if any of these files (“~/.bash_profile“, “~/.profile“, “~/.bash_login“) do not exist in your home directory, you can manually create them using your choice of text editor.
However, in an interactive, non-login shell, it will only look for the existence of the “~/.bashrc” file and will load the environment variables and customizations in your current shell environment.
That’s all you need to know; going more in depth might make you more confused on these simple terms.
If you have any suggestions that must be included in this article, then let us know in the comment section.
Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.