Interactive shell and non-interactive shell,login shell and non-login shell. First, this is divided into two different dimensions, one is interactive, and the other is whether to log in or not. .
The interactive mode is where the shell waits for your input and executes the commands you submit.
non-interactive mode, script.
Login Shell: A shell that requires a username, password login to enter (or shell generated through the "–login" option)
- The top-level shell you get when you log in to your system, whether you're logged in via a local terminal or via a network ssh. The login shell obtained in this case is an interactive shell.
- You can get an interactive login shell by calling bash with the--login option under terminal.
- Use the--login option in the script to invoke bash (for example, in the first line of the shell script as specified below: #!/bin/bash--login), you get a non-interactive login shell.
- When you use "Su-" to switch to the specified user, you get the login shell for this user. If you do not use "-", you get the non-login shell.
non-login Shell: Of course, you do not need to enter a user name and password to open the shell, for example: direct command "Bash" is to open a new non-login shell, in GNOME or KDE open a "terminal" The (terminal) window program is also a non-login shell.
The main difference between the Non-login shell and the login shell is that they read different configuration files when they start, causing the environment to differ. Login Shell starts by reading the/etc/profile global configuration first, then looking for one in the ~/.bash_profile, ~/.bash_login, ~/.profile three configuration files, and reads the first one found to ignore the rest. The login shell reads and executes the commands in ~/.bash_logout when it exits.
The interactive Non-login shell reads the ~/.BASHRC resource file when it starts. The non-interactive non-login shell does not read all of the above configuration files, but instead looks for the environment variable bash_env, reading and executing the commands in the file that bash_env points to.
(1) config file read by login Shell
/etc/profile the file to set the overall environment of the system, usually the configuration of some environment variables.
One of the three ~/.bash_profile or ~/.bash_login or ~/.profile, which is the user's personal settings
(2) Non-login Shell Read configuration file
~/.bashrc
Usually we want to customize some configurations, write the configuration in ~/.BASHRC, and then read the ~/.BASHRC in ~/.bash_profile, which ensures that the login shell and the interactive non-login shell get the same configuration. As for/etc/profile do not easily change, after all, will affect the overall system configuration.
Shell's various operating modes?