Three ways to start bash shell
1, log in as the default login shell
2. Interactive shell as a non-login shell
3. As a non-interactive shell for running scripts
First, login shell
When you log in to a Linux system, the bash shell starts as a login shell, and the login shell reads commands from 4 different boot files, the sequence in which the bash shell processes these files:
1./etc/profile
2. $HOME/.bash_profile
3. $HOME/.bash_login
4. $HOME/.profile
Where the/etc/profile file is the system's default bash Shell master boot file, each user on the system will execute the boot file when logging on, and the other three boot files are user-specific. For example, each user can configure their own JDK, Tomcat, and so on.
1),/etc/profile
The profile file has a complex feature, with a for statement that accesses each file in the/ETC/PROFILE.D directory one at a time, providing a Linux system with a centralized location for the application-specific startup files to be executed when the user logs in. These are basically related to the specific application of the system, most applications will create two boot files, one for bash shell, one for C shell,
2), $HOME directory of startup files
Most Linux distributions use only one of these three boot files, and each user can edit the files and add their own environment variables to start each bash shell session.
. bash_profile file: This file will first check if there is a boot file called. BASHRC in the home directory, and if so, the startup file will first execute the command in the. bashrc file, and then add a directory to the PATH environment variable.
Second, interactive shell
If the bash shell starts when it is not logged on to the system, such as by entering the Bash command at the command line prompt, this startup shell is called the interactive shell, in which case the/etc/profile file is not started. And will go to the user's home directory to check whether BASHRC exists. This file has two functions:
1. View the common BASHRC file in the/etc directory
2. Provides a place for users to customize their own command aliases and private script functions.
The generic/ETC/BASHRC boot file is executed by each user who initiates an interactive shell session on the system
Third, non-interactive shell
This is the shell used by the system to execute shell scripts. In this case, there is no need to worry about it without a command line prompt, but when you run a script on the system and still run a specific startup command, in order to handle this situation, the bash shell provides a base_env environment variable that, when the shell launches a non-interactive shell process, It checks the environment variable to see which startup file to execute, and if it does, the shell executes the command in the file.
Three ways to start the bash shell, check the startup file