Why do we have login, non-login, interactive, and non-interactive bash shells?
Solution 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, subsectionset
:-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.