用户登录之后默认shell------bash的动作

来源:互联网 发布:俞长栋数据 编辑:程序博客网 时间:2024/06/05 12:38
Locating System Environment Variables
The Linux system uses environment variables to identify itself in programs and scripts. This provides
a convenient way to obtain system information for your programs. The trick is in how these
environment variables are set.
When you start a bash shell by logging in to the Linux system, by default bash checks several
files for commands. These files are called startup files. The startup files bash processes depend on
the method you use to start the bash shell. There are three ways of starting a bash shell:
■ As a default login shell at login time
■ As an interactive shell that is not the login shell
■ As a non-interactive shell to run a script
The following sections describe the startup files the bash shell executes in each of these startup
methods.
Login shell
When you log in to the Linux system, the bash shell starts as a login shell. The login shell looks for four different startup files 
to process commands from. The order in which the bash shell
processes the files is:
■ /etc/profile
■ $HOME/.bash profile
■ $HOME/.bash login
■ $HOME/.profile
The /etc/profile file is the main default startup file for the bash shell on the system. ---Every user ---on the system executes 
this startup file when they log in. The other three startup files are specific for each user and can be customized for each user’s requirements.

Let’s take a closer look at these files.


The $HOME startup files
The remaining three startup files are all used for the same function — to provide a user-specific
startup file for defining user-specific environment variables. Most Linux distributions use only
one of these three startup files:
■ $HOME/.bash profile
■ $HOME/.bash login
■ $HOME/.profile

There are several startup files that the bash shell executes when it starts up. These startup files
can contain environment variable definitions to set standard environment variables for each
bash session. When you log in to the Linux system, the bash shell accesses the /etc/profile
startup file, and also three local startup files for each user, $HOME/.bash profile, $HOME/
.bash login, and $HOME/.profile. Users can customize these files to include environment
variables and startup scripts for their own use.

原创粉丝点击