So the bash man pages explain what login and interactive shells are:

A login shell is one whose first character of argument zero is a -, or one started with the --login option.

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.

I think this means we can have 4 different types of shells:

  • Interactive login shells,
  • Non-interactive login shells,
  • Interactive non-login shells,
  • Non-interactive non-login shells

But why do we have interactive/non-interactive and login/non-login shells in the first place? Why the variety? What would we lose if we only had one type of shell?

Also when trying to determine if I am in a login shell by running echo $-, it outputs:


Some of these flags are explained here, but h, H, and m are not explained. Is there a place that describes all these flags?

1 Answer 1


These are my thoughts on the different "types"of shells -- unfortunately I didn't witnessed the rise of the Un*x right from the beginning (I assume this concept is grown historically to a good extend), so please be critical.

  • When I log into a system (nowadays via the graphical X login), there might be some tasks which should run once, e.g. establish a connection to some kind of server, present me a the today's todo list, autostart some commands, etc. This shouldn't happed every time I open up a new terminal. So there's a set of config files (/etc/profile, ~/.bash_login and so on, refer to the manual for an accurate list) sourced only by login shells.
  • Accordingly, to close the connections, kill some programs, run a backup script there is ~/.bash_logout when the login shell exists.
  • so, the "normal" shell I use in a terminal, shouldn't ba a login shell, but nevertheless should read my personal preferences from ~/.bashrc, because I want my keybindings to interact with the shell -- hence this is an interactive, non-login shell.
  • and last, but not least when bash is used for scripting, neither of this is important. bash should start as fast as it can, i.e. shouldn't read any config files. This is a non-interactive, non-login shell.

So, my answer to your question What would we lose if we only had one type of shell? is in one word: "Flexibility."

The answer to your second question is easy:

$- lists the current set of options. These can either be set by command line parameters to bash or via the set builtin. So you have to look at two places in the manual:

  • OPTIONS section:

    -i        If the -i option is present, the shell is interactive.
  • SHELL BUILTIN COMMANDS section, subsection set:

    -h      Remember the location of commands as they are looked up for execution.  This is enabled by default.
    -m      Monitor  mode.  Job control is enabled.  This option is on by default for interactive shells on systems that sup‐
            port it (see JOB CONTROL above).  Background processes run in a separate process  group  and  a  line  containing
            their exit status is printed upon their completion.
    -B      The shell performs brace expansion (see Brace Expansion above).  This is on by default.
    -H      Enable !  style history substitution.  This option is on by default when the shell is interactive.
  • 1
    Woo I believe @mpy answer to OP's clearly formulated question is able to succesfully desambigious some rather useful definition. About that: So, a non-login shell just is a subset of the login shell right?
    – tuk0z
    Dec 24, 2015 at 16:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .