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:
himBH
Some of these flags are explained here, but h
, H
, and m
are not explained. Is there a place that describes all these flags?
Best Answer
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.
/etc/profile
,~/.bash_login
and so on, refer to the manual for an accurate list) sourced only by login shells.~/.bash_logout
when the login shell exists.~/.bashrc
, because I want my keybindings to interact with the shell -- hence this is an interactive, non-login shell.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 tobash
or via theset
builtin. So you have to look at two places in the manual:OPTIONS
section:SHELL BUILTIN COMMANDS
section, subsectionset
: