The difference between the login shell and the Non-login shell

Source: Internet
Author: User

"Thedifference between the login shell and the Non-login shell "

    • Login Shell: A full login process is required to go to bash. That is, by entering the account and password to log into the system, the obtained shell is called the login shell
    • non-login Shell: The method of obtaining the Sbash interface does not require a repeat login action. If you log in to Linux with X window, and then start the terminal with the graphical interface of X, the terminal does not need to enter the account and password, the bash environment is non-login shell. The bash command was executed again in the original bash environment, and no account password was entered to enter the new bash environment (the previous bash subprocess), and the new bash was the Non-login shell.

So, what is the difference between the two?

Login Shell: When logged in this way, the shell will re-read/etc/profile and ~/.bash_profile to apply the new environment variable.
Non-login Shell: At this point the shell does not read the/etc/profile and ~/.bash_profile, but instead reads the ~/.BASHRC to apply the new environment variable. The words headline is the difference and influence, the influence thing naturally originates from the difference. Back to the beginning of the question, SU switch user did not get the user's environment (then the command is "Su Xxoo", here Xxoo for the user to switch, the command executed as root), it seems that the problem is in this synchronicity login mode, according to the phenomenon we can Judge Su Xxoo executed the Non-login shell.

To verify the above judgment, we looked at the simple help of the SU command:

[email protected] ~]# su--help
USAGE:SU [OPTION] ... [-] [USER [ARG] ...]
Change the effective user ID and group ID to that of user.

-,-L,--login make the shell a login shell


Obviously, my judgment is correct, and by default it is the Non-login shell that executes because the login shell needs to be appended with the parameter "-" or "-l" or "--login" after Su. So to get the user's environment variables after Su, you need to execute a command like "Su-xxoo".

There are also three additional tips:

PS1:bash reads individual profiles for each account after reading/etc/profile, with three personal profiles read: ~/.bash_profile,~/.bash_login,~/.profile. In fact, Bash reads only one of the above three files, and the order in which they are read is the order above. That is, Bash looks for the three personal profiles listed above, and once they find one, the subsequent files are no longer read.

PS2: when logging in with Non-login shell, if you want to get the user's environment variables, execute "source ~/.bash_profile" (. Bash_profile depending on the situation may also be. Bash_ Login or. Profile, where source can be replaced with a decimal point, which is "source ~/.bash_profile" equivalent to ". ~/.bash_profile ". The explanation of the source command can be searched by itself.

PS3: In fact, some Linux distributions of the login shell will also read. bashrc files, such as Fedora11 in the "Vim ~/.bash_profile" will find "if [-f ~/.BASHRC]; Then. ~/.BASHRC fi ". Here, PS2 is used to replace the source attribute with the decimal point, where./bash_profile reads the execution. bashrc file.

Reference: http://blog.sina.com.cn/s/blog_59c0a56201016im6.html

The difference between the login shell and the Non-login shell

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.