112

Possible Duplicate:
Difference between Login Shell and Non-Login Shell?

I have been looking at /etc/profile and /etc/bash.bashrc to see how they are run, and notice that some are executed by non-login shells, some work with interactive shells, etc.

What are the differences in this type of shells, i.e., interactive & non-interactive, login & non-login, etc.?

The question may be pretty basic, but it seems I need to ask what a shell is, first and foremost. What is a shell, what is its relevance, how do you use it, and why does it exist to start with?

Update: To make the intent of the question better understood, what I need to understand besides the definitions, are the use cases for one type of shell or the other. It is the use cases that help understanding, not just dictionary definitions.

vfclists
  • 7,531
  • 14
  • 53
  • 79

2 Answers2

127

A shell is the generic name for any program that gives you a text-interface to interact with the computer. You type a command and the output is shown on screen.

Many shells have scripting abilities: Put multiple commands in a script and the shell executes them as if they were typed from the keyboard. Most shells offer additional programming constructs that extend the scripting feature into a programming language.

On most Unix/Linux systems multiple shells are available: bash, csh, ksh, sh, tcsh, zsh just to name a few. They differ in the various options they give the user to manipulate the commands and in the complexity and capabilities of the scripting language.

Interactive: As the term implies: Interactive means that the commands are run with user-interaction from keyboard. E.g. the shell can prompt the user to enter input.

Non-interactive: the shell is probably run from an automated process so it can't assume it can request input or that someone will see the output. E.g., maybe it is best to write output to a log file.

Login: Means that the shell is run as part of the login of the user to the system. Typically used to do any configuration that a user needs/wants to establish his work environment.

Non-login: Any other shell run by the user after logging on, or which is run by any automated process which is not coupled to a logged in user.

Tonny
  • 1,733
  • 6
    So, when I'm in a Linux GUI (Mint 17.1 Cinnamon for example) and I launch a Terminal (gnome-terminal for example), am I launching an "interactive shell"? Is this ALSO a "login shell", or is a "login shell" only when my user profile logs in to the OS (like right after boot)? – Jon Wadsworth May 22 '15 at 18:53
  • 9
    @JonWadsworth Yes, it's interactive. But, it is NOT a login shell. Effectively your XWindows GUI environment (Cinnamon in your case) acts as a sort-of login-shell substitute. Purists will not call XWindows a shell, becasue it is graphical in stead of text-based, but let's be honest. It serves the same purpose: Gives you a launcher to start other programs, including Terminal to get a text-based shell again. – Tonny May 22 '15 at 19:06
  • 4
    So, I am running OSX and I am already logged in and working. Now I run the terminal app to do some work in command prompt. I am obviously in an interactive shell. But am I in a login shell, or is that considered a non-login shell? – retrography Dec 02 '15 at 20:11
  • Inside the crontab, would the commands be executed as a non-login, non-interactive shell? (Because there's no logging in action, nor is there any interactivity) – CMCDragonkai Dec 11 '15 at 06:48
  • 2
    Thank you for splitting them in readable chunks. Makes it more understandable than the ones I got from the Possible Duplicate link and some old documentations online. – JohnnyQ Sep 21 '16 at 07:08
  • 7
  • Does login imply interactive? – Saddle Point Feb 05 '21 at 04:43
  • @stackunderflow Usually, but it is not strictly required. You can, in theory, have a system (some embedded device maybe) that automatically starts a login shell, but can't be used interactively. – Tonny Feb 05 '21 at 14:33
12

It might be strange to realize for some of people who never had a comp disconnected from Internet, that lots of answers regarding UNIX systems are already shipped with them. For e. g., man bash, "Invocation" section:

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 (as determined by isatty(3)), or one started with the -i option. PS1 is set and $- includes i if bash is interactive, allowing a shell script or a startup file to test this state.

poige
  • 6,231
  • @vfclists, man getty? :) Then when it mentions loginman login. And so on. ;) P. S. Sometimes there would be a gap in those docs, then you can try searching inside /usr/share/doc or invoke GNU's info. – poige Oct 11 '12 at 20:15
  • 1
    @vfclists the login and getty processes handle the user/id password check. When that is successfull they look in /etc/passwd which shell is the default for the user. That shell is started as login shell. If you started a terminal session from a GUI environment the terminal program would do the same. (Except for the userid/password check as you are obviously already logged on.) –  Oct 11 '12 at 21:57
  • 19
    That doesn't really answer the OP's question, this information is only comprehensible to someone familiar with the concepts – and it's also specific to bash. – yerforkferchips Mar 27 '17 at 10:53