Shell logon mode and corresponding configuration files

Source: Internet
Author: User

Refer to Linux Command, editor and shell programming (Tsinghua University Press)

When shell is started, it will run the Startup File to initialize itself. The specific file to run depends on whether the shell is a login shell or a non-Login Shell interactive mode (such as through bash), or a non-interactive shell (used to execute shell scripts ). In the Startup FileCommandThe user must have the read permission, and the general Linux release version will put the corresponding commands in some startup files.

1: Interactive Shell Login

Interactive Shell logon refers to the shell used when a user logs on to the system (which can be specified by default, such as bash shell ). When you log on to shell, you will find several startup files to process the commands. The order in which bash shell processes the files is as follows:

/Etc/ProFileShell first executes the command in/etc/profile. After setting this file, you can create default features for all bash users in the system (Linux of different versions have different commands placed in this file );

~ /. Bash_profile ,~ /. Bash_login ,~ /. ProfileShell searches for these files in sequence and runs the commands in the first file it finds. You can place commands in these files to override the default settings in the/etc/profile file;

~ /. Bash_logoutWhen a user logs out, bash executes the file ~ /. Bash_logout command. This file contains the cleanup Command executed when the session is exited, for example, deleting a temporary file;

 

2: Interactive non-Login Shell

Interactive non-Login Shell refers to an interactive non-Login Shell if a bash shell is started without an equal recording system (such as typing bash at the CLI prompt. Interactive non-login shell does not execute the commands in the startup file mentioned above, but interactive non-Login Shell inherits the shell variables set by these startup files from the login shell.

/Etc/bashrcAlthough it is not directly called through bash, many ~ /. Bashrc file call/etc/bashrc. This setting allows the super user to create default properties for non-login shell in the system.

. BashrcInteractive non-Login Shell execution ~ The command in the/. bashrc file, and the shell Startup File (such as. bash_profile) usually runs this file. In this way, the command in. bashrc can be run in both the login shell and non-login shell.

 

3: non-interactive shell

Non-interactive shell refers to running in shell script mode. In this mode, the shell does not interact with the user at runtime (unless you need to specify the running parameters), but instead reads and executes the commands stored in the file. When it reads the end of the file, shell is terminated. These shells inherit the shell variables set by these startup files from the login.

Bash_envThe non-interactive shell searches for the environment variable bash_env (or env when called as SH) and executes the commands in the file named after this variable.

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.