HOWTO · Linux
Difference Between a Login Shell and a Non-Login Shell
This tutorial explains the difference between a login shell and a non-login shell in UNIX-based systems.
On this page
A login shell and a non-login shell differ in how the shell was started, which affects startup configuration. This guide explains the distinction on UNIX-based systems and uses Bash to show how to check shell status and choose an invocation. Login status is separate from whether a shell is interactive.
What Is a Shell?
A shell is a program that reads commands and asks the operating system to run them. Bash is one common shell. A shell can also read configuration files that set variables, define aliases, and configure the prompt. Which files Bash reads depends on how it was invoked, so the same user can see different settings in different sessions.
Two properties matter here: a shell is a login shell when it is invoked in login mode, and it is interactive when it reads commands from a user-facing prompt. These properties are independent. A terminal can start an interactive non-login shell, and a script can start a non-interactive shell.
Login Shells and Non-Login Shells
A login shell is a shell invoked in login mode. For Bash, this includes an invocation with --login or a login-style invocation name. This status describes how the shell was invoked; by itself, it does not prove that authentication occurred or that a user login session began. A text console login, SSH, and tools that switch users are common contexts where a login shell may be started, depending on the command and configuration. The shell is not defined as the first process launched by /bin/login; that program is one possible part of a login path.
A non-login shell is started without login mode. It often appears when an interactive shell starts another shell, or when a terminal emulator opens a new prompt. A shell started to run a command or script is typically non-interactive, and is not necessarily a login shell. These are common patterns, not guarantees about every terminal or service.
| Property | Login shell | Non-login shell |
|---|---|---|
| Meaning | Invoked in login mode | Invoked without login mode |
| Typical configuration | Login startup files | Interactive Bash usually reads ~/.bashrc |
| Independent property | May be interactive or non-interactive | May be interactive or non-interactive |
How Bash Startup Files Differ
For Bash, a login shell reads /etc/profile, then the first readable user file among ~/.bash_profile, ~/.bash_login, and ~/.profile. These files can source other configuration. Bash does not universally load ~/.bashrc from a login file; users often add that line themselves. An interactive non-login Bash reads ~/.bashrc. A non-interactive Bash uses BASH_ENV when that variable names a file. Distribution files such as /etc/bashrc or files under /etc/profile.d are included by system or user configuration on some systems, rather than by one universal Bash sequence.
The order matters because later assignments can replace earlier values. If a setting appears in one kind of session but not another, first identify the shell’s login and interactive status, then check the corresponding startup file and any files it sources. Changing startup files affects future shells; it does not automatically update an already-running shell.
How to Identify and Start Each Shell Type
In Bash, the login_shell shell option is a direct check for login status. shopt -q returns success when the option is on. The $0 name may begin with - for a login shell, but programs and wrappers can change that name, so it is a clue rather than a definitive test. To check interactivity separately, test the $- flags for i.
Run this Bash example to inspect the current shell and start a child shell with an explicit mode:
printf 'Current Bash login status: '
if shopt -q login_shell; then
printf 'login\n'
else
printf 'non-login\n'
fi
printf 'Child Bash login status: '
bash --login -c 'if shopt -q login_shell; then printf "login\\n"; else printf "non-login\\n"; fi'
case $- in
*i*) printf 'Current Bash is interactive\n' ;;
*) printf 'Current Bash is non-interactive\n' ;;
esac
Current Bash login status: non-login
Child Bash login status: login
Current Bash is non-interactive
Use bash --login to request a login Bash and bash to start a non-login Bash. Add -i when you specifically need an interactive child shell; an interactive shell is not automatically a login shell. For example, bash --login -i requests both properties. When testing startup behavior, use a fresh shell and account for local configuration, which may source additional files.