Black Friday 2025 – NPI EA (cat = Baeldung on Linux)
announcement - icon

Yes, we're now running our Black Friday Sale. All Access and Pro are 33% off until 2nd December, 2025:

>> EXPLORE ACCESS NOW

Baeldung Pro – Linux – NPI EA (cat = Baeldung on Linux)
announcement - icon

Learn through the super-clean Baeldung Pro experience:

>> Membership and Baeldung Pro.

No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.

Partner – Orkes – NPI EA (tag=Kubernetes)
announcement - icon

Modern software architecture is often broken. Slow delivery leads to missed opportunities, innovation is stalled due to architectural complexities, and engineering resources are exceedingly expensive.

Orkes is the leading workflow orchestration platform built to enable teams to transform the way they develop, connect, and deploy applications, microservices, AI agents, and more.

With Orkes Conductor managed through Orkes Cloud, developers can focus on building mission critical applications without worrying about infrastructure maintenance to meet goals and, simply put, taking new products live faster and reducing total cost of ownership.

Try a 14-Day Free Trial of Orkes Conductor today.

1. Overview

The shell is a command line interpreter in Linux. It’s a program that receives commands from the user and gives them to the operating system to execute. Further, bash is the default login shell for most Linux distributions, but there are other Linux shells like the Korn shell (ksh), the Z shell (zsh), and the C shell (csh).

In this tutorial, we’ll learn the difference between interactive, non-interactive, login, and non-login shells.

2. Interactive Login Shell

An interactive shell receives commands from the user and displays output to the user. Moreover, users get a login shell when they login to their account.

We get an interactive login shell when we use programs like ssh or telnet:

$ ssh localhost
$ echo $-
himBHs
$ shopt login_shell
login_shell    	on

In the above snippet:

  • $- is a special bash parameter that returns the option flags used in the current bash shell. Further, if it includes i, it means that the shell is interactive
  • shopt login_shell tells us if the login_shell shell option is set

Thus, we have an interactive login shell.

3. Interactive Non-login Shell

We get an interactive non-login shell when we open up a terminal on our Linux machine:

$ echo $-
himBHs
$ shopt login_shell
login_shell    	off

We can see that we got an interactive, non-login shell.

4. Non-interactive Login Shell

If we give something other than tty (for example, a command) as stdin to ssh, we receive a non-interactive login shell:

$ echo 'echo $-; shopt login_shell' | ssh localhost
Pseudo-terminal will not be allocated because stdin is not a terminal.
hBs
login_shell    	on

In the above snippet, we passed ‘echo $-; shopt login_shell’ as stdin to ssh. As a result, we got a non-interactive login shell.

5. Non-interactive Non-login Shell

Finally, we get a non-interactive non-login shell when we run a script on our machine. That is because they run in their new shell that is non-interactive:

$ echo 'echo $-; shopt login_shell' > script.sh
$ chmod +x script.sh 
$ ./script.sh 
hBH
login_shell    	off

To clarify, we wrote ‘echo $-; shopt login_shell’ into script.sh and then made it executable using chmod. After that, we ran the script.

As we can see, we got a non-interactive non-login shell.

6. Conclusion

In this article, we learned about the different kinds of shells we can get in the Linux environment.