What is the difference between interactive shells, login shells, non-login shell and their use cases?
differences between login shell and interactive shell
Why do we have login, non-login, interactive, and non-interactive bash shells?
What is the difference between a ‘Login’ and an ‘Interactive’ bash shell
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 if 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.
USER PID TTY COMMAND root 723 ? /usr/sbin/sshd -D root 1023 ? \_ sshd: andreas [priv] andreas 1062 ? | \_ sshd: andreas@pts/0 andreas 1063 pts/0 | \_ -bash root 1320 pts/0 | \_ sudo -s root 1321 pts/0 | \_ /bin/bash root 1456 pts/0 | \_ ps auxf root 1271 ? \_ sshd: andreas [priv] andreas 1307 ? \_ sshd: andreas@pts/1 andreas 1308 pts/1 \_ -bash root 760 ttyS0 /bin/login -- andreas 849 ttyS0 \_ -bash andreas 1464 ttyS0 \_ bash
A login shell is the first process that executes under your user ID when you log in for an interactive session. The login process tells the shell to behave as a login shell with a convention: passing argument 0, which is normally the name of the shell executable, with a – character prepended (e.g. -bash whereas it would normally be bash.
sudo
see also here:
blog.bachi.net: bashrc vs. bash_profile
[...] -i, --login Run the shell specified by the target user's password data- base entry as a login shell. This means that login-specific resource files such as .profile or .login will be read by the shell. If a command is specified, it is passed to the shell for execution via the shell's -c option. If no command is specified, an interactive shell is executed. sudo attempts to change to that user's home directory before running the shell. The command is run with an environment similar to the one a user would receive at log in. The Command environment section in the sudoers(5) manual documents how the -i option affects the environment in which a command is run when the sudoers policy is in use. [...] -s, --shell Run the shell specified by the SHELL environment variable if it is set or the shell specified by the invoking user's pass- word database entry. If a command is specified, it is passed to the shell for execution via the shell's -c option. If no command is specified, an interactive shell is executed. [...]
Pingback: bashrc vs. bash_profile | Andreas' Blog