Shell's various operating modes?

Source: Internet
Author: User

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)

    1. 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.
    2. You can get an interactive login shell by calling bash with the--login option under terminal.
    3. 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.
    4. 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?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.