What is a login shell and interactive shell, and what is a .bash_profile and .bashrc?
What are the differences between a login shell and interactive shell?
47k views Asked by caesar At
2
There are 2 answers
0
On
Since you probably know what a "shell" is and are using it your question only targets the difference between login shell and everything else...
A login shell only differs from any other shell by the fact that one or more initial setup scripts (resources) are loaded on startup, typically named with "profile" in their name. in there basic settings are defined that are derived to subsequently opened shells (so they only need to be defined once).
[gnu bash manual]
A login shell is a shell where you login. You can recognize a login shell from a
ps -flisting, it will have a hyphen at the start of the program name, for example:An interactive shell is one which reads commands from its standard-input, usually a terminal.
For example,
putty, then the session is both a login shell and an interactive one.bashthen you enter an interactive shell, but it is not a login shell.If a shell script (a file containing shell commands) is run, then it is neither a login shell nor an interactive one.
Start-up files are highly tailorable in bash:
When a login bash shell is invoked, then
/etc/profileis sourced (executed in the current environment). After that, three files are checked for existence. The checks for these files are done in this order, the first one that exists is run.~/.bash_profile~/.bash_login~/.profileOnce a match is found, the other files are ignored, even if they exist. The
/etc/bashrcfile might be used by both the~/.bash_profileand the~/.bashrcfiles. That would mean that the/etc/bashrcfile is sourced on all interactive invocations of bash, whether it is a login or non-login shell.So, the
.bashrcfile is also run every time you request a new interactive shell. This does not include a shell script. Normally variables, aliases or functions are placed in this file.Bash shell scripts read a different file if suitably instructed. If the user defines (usually in their own
.bash_profile) a variableBASH_ENVwhich contains a filename, scripts will read this. If this variable is not set (and exported) then bash scripts will not read any startup files.