Differences between Linux Login Shell and Non-Login Shell: Merely a Matter of File Sourcing
When it comes to Linux shells, there are two main types: Login Shell and Non-Login Shell. While these two types of shells have some differences, the primary difference between them is how they handle file sourcing.
Login Shell
A Login Shell is the first process that runs when a user logs in to a Linux system. It reads and executes the shell profile file, which is usually located at ~/.bash_profile or ~/.bashrc depending on the distribution. This file contains various configurations and settings that are specific to the user's environment.
Non-Login Shell
A Non-Login Shell, on the other hand, is any shell that is started after the user has already logged in. This includes shells started from a terminal window or from a script. Non-Login Shells do not read and execute the shell profile file by default. Instead, they read and execute the ~/.bashrc file.
File Sourcing
The main difference between Login Shell and Non-Login Shell is how they handle file sourcing. In a Login Shell, the shell profile file is sourced, which means that its contents are executed in the current shell environment. In a Non-Login Shell, the ~/.bashrc file is sourced instead.
However, it is possible to source the shell profile file in a Non-Login Shell by using the source or . command. This is useful when you want to apply the configurations and settings from the shell profile file to the current shell environment.
Why Does it Matter?
Understanding the difference between Login Shell and Non-Login Shell is important because it can affect how your shell environment is configured. For example, if you have environment variables or aliases that you want to be available in all shells, you should put them in the shell profile file. However, if you have configurations that are specific to interactive shells, you should put them in the ~/.bashrc file.
In conclusion, the difference between Linux Login Shell and Non-Login Shell is merely a matter of file sourcing. While Login Shells source the shell profile file, Non-Login Shells source the ~/.bashrc file. However, it is possible to source the shell profile file in a Non-Login Shell by using the source or . command. Understanding this difference is important for configuring your shell environment correctly.
References
- Bash Reference Manual, Invoking Bash
- GNU Bash, About GNU Bash
- Unix & Linux Stack Exchange, Difference between Login Shell and Non-Login Shell