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

本文介绍了Linux系统中环境变量的作用及设置方法。详细解释了登录Shell启动时如何通过不同的配置文件来定义和定制环境变量,包括系统级的 /etc/profile 和用户级的 $HOME/.bashprofile 等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值