etc / profile / etc / bashrc ~ / .bash_profile ~ / .bashrc like profile difference

We must first understand what is an interactive shell and non-interactive shell, what is the login shell and non-login shell. 

The interactive mode shell is waiting for your input, and execute commands you submit. This mode is called an interactive because the shell interacts with the user. This model is also very familiar with most users: login, execute commands, sign-off. When you sign back, shell have terminated.

Non-interactive mode. In this mode, shell do not interact with you, but read commands stored in a file and execute them. When the end of the file it read, shell will cease.

login shell is the need to enter a user name and password to log shell, such as boot shell landed, ssh login, su - (no password is required when switching from root to another user) username.

non-login shell without a password, such as bash, su username, open the graphical interface bash.

 

/ etc / profile: This file is set up for each user environment information system, when a user first logs in, the file is executed and collect shell settings from the configuration file /etc/profile.d directory.

/ etc / bashrc: execute this file to the user for each run when the bash shell bash shell is opened, the file is read.

~ / .bash_profile: Each user can use the file input information specific to shell their own use, when a user logs in, the file is performed only once by default, he set some environment variables, execute .bashrc file users!. 

~ / .bash_login: if the login mode is performed bash is, read ~ / .bash_profile, if it does not exist, the read ~ / .bash_login, if the first two do not exist, the read ~ / .profile.

~ / .profile: if the login mode bash is executed, read ~ / .bash_profile, if it does not exist, the read ~ / .bash_login, if the first two do not exist, the read ~ / .profile Further,. when the log graphics mode, this file will be read, even if there is ~ / .bash_profile and ~ / .bash_login.

 ~ / .bashrc: This file contains dedicated to the bash shell bash your information, log on, and when every time you open a new shell when the the file is read.

~ / .bash_logout: each time when the system exits (exit bash shell), the file is executed. That is, when the text mode cancellation, this file will be read, written off when graphics mode, the file will not be read.

 
Here are a few examples of the machine: 

First need to be clear that read ~ / .bash_profile, this file will be to read ~ / .bashrc, and ~ / .bashrc will go to read / etc / bashrc. So long as the read ~ / .bash_profile, it will read ~ / .bashrc and / etc / bashrc simultaneously.

1. Log in graphics mode, sequential read: / etc / profile and ~ / .profile.

2. log graphics mode, when the terminal is opened, sequential read: ~ / .bashrc and / etc / bashrc.

3. Log text mode are sequentially read: /etc/profile,~/.bash_profile,~/.bashrc and / etc / bashrc. 

4. su from other users to the user, then two cases:    

   (1) If the -l option (or - parameters, - Login parameters), such as: su -l username, the lonin bash is, it will sequentially read the following profile: /etc/profile,~/.bash_profile , ~ / .bashrc and / etc / bashrc.    

   (2) If there is no band -l, bash is non-login, the sequence will read: ~ / .bashrc and / etc / bashrc and inherits from its parent process environment variables.

5. logout, or exit su login user, if it is longin way, then bash reads: ~ / .bash_logout

6. Perform a custom shell file, the use of "bash -l a.sh" the way, the bash will read the line: /etc/profile,~/.bash_profile,~/.bashrc and / etc / bashrc, call bash with sh -l a.sh, it will execute the / etc / profile and ~ / .profile. If you use other methods, such as: bash a.sh, ./a.sh,sh a.sh, you will not read any file above, can only inherit environment variables from its parent Department, and so can not be inherited as alias used.

The above Examples 7 to read all ~ / .bash_profile, if the file does not exist, the read ~ / .bash_login, if the first two do not exist, the read ~ / .profile. 

Go https://www.cnblogs.com/Monitor/p/4020223.html

Guess you like

Origin www.cnblogs.com/lichihua/p/11574966.html