Check the Startup File in three ways to start bash shell,

Source: Internet
Author: User

Check the Startup File in three ways to start bash shell,

Three methods to start bash shell

1. Use the default logon shell

2. Interactive shell as a non-Logon shell

3. non-interactive shell used as a script


1. log on to shell

When you log on to Linux, the bash shell will be started as the login shell, and the login shell will read commands from four different startup files. The following is the order in which the bash shell processes these files:


2. $ HOME/. bash_profile

3. $ HOME/. bash_login

4. $ HOME/. profile

The/etc/profile file is the main Startup file of the system's default bash shell. Every user on the system will execute this startup file upon logon. The other three startup files are proprietary to users. For example, each user can configure their own jdk and tomcat.


The profile file has a complex feature and has a for statement that will access/etc/profile one by one. each file in the d directory provides a Linux system with a place to centrally store the exclusive Startup file of the application to be executed during user logon. These are basically related to specific system applications. Most applications create two startup files, one for bash shell and the other for c shell,


2) Start files in the $ HOME directory


Most Linux distributions only use one of these three startup files. Each user can edit these files and add their own environment variables to start each bash shell session for them.

. Bash_profile file: This file will first check whether there is another name in the HOME directory. bashrc Startup File. If yes, the startup file will be executed first. in the bashrc file, add a directory to the path environment variable.



2. Interactive shell

If the bash shell is not started when you log on to the system, for example, enter the bash command at the command line prompt to start. The started shell is called the interactive shell, in this case, the/etc/profile file will not be started, but the bashrc will be checked in the user's HOME directory. This file has two functions:

1. view the shared bashrc file under the/etc directory

2. provides users with a place to customize their own command aliases and private script functions.

The common/etc/bashrc Startup File is executed by every user who starts an interactive shell Session on the system.


Iii. Non-Interactive shell

This shell is used when the system executes shell scripts. In this case, you do not need to worry that it does not have a command line prompt, but you still need to run a specific startup command every time you run the script on the system. To handle this situation, bash shell provides the BASE_ENV environment variable. When the shell starts a non-interactive shell process, it checks the environment variable to view the Startup file to be executed, shell will execute commands in the file.

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: 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.