当前位置:网站首页>bashrc与profile
bashrc与profile
2022-07-07 12:12:00 【sinat_36789271】
导读:交互式shell和非交互式shell; login shell 和non-login shell
交互式模式就是shell等待你的输入,并且执行你提交的命令。这种模式被称作交互式是因为shell与用户进行交互。这种模式也是大多数用户非常熟悉的:登录、执行一些命令、签退。当你签退后,shell也终止了。 shell也可以运行在另外一种模式:
非交互式模式。在这种模式下,shell不与你进行交互,而是读取存放在文件中的命令,并且执行它们。当它读到文件的结尾,shell也就终止了。
一、bashrc与profile都用于保存用户的环境信息。下面逐一介绍:
/etc/profile(全局,用于交互式login shell):此文件为系统的每个用户设置环境信息,当第一个用户登录时,该文件被执行。并从/etc/profile.d目录的配置文件中搜集shell的设置。
当对/etc/profile有修改的话必须得重启修改才会生效,此修改对每个用户都生效。
/etc/pro.d:.d表示目录,目录中存放的是一些应用程序所需的启动脚本,其中包括了颜色、语言、less、vim及which等命令的一些附加设置。这些脚本文件之所以能够被自动执行,是因为在/etc/profile中使用一个for循环语句来调用这些脚本。而这些脚本文件是用来设置一些变量和运行一些初始化过程的。
# 例如:
# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.
if [ -d /etc/profile.d ]; then # 判断/etc/profile.d 是不是一个目录
for i in /etc/profile.d/*.sh; do #如果是一个目录,到该目录下,取出每一个shell程序
if [ -r $i ]; then #如果该shell可以执行
. $i # 则执行它
fi
done
unset i
fi/etc/bashrc(全局,用于非交互式non-loginshell):为每一个运行bash shell的用户执行此文件。当bash shell被打开时,该文件被读取(有些linux版本中的/etc目录下已经没有了bashrc文件)。
如果你想对所有的使用bash的用户修改某个配置并在以后打开的bash都生效的话可以修改这个文件,修改这个文件不用重启,重新打开一个bash即可生效。
~/.bash_profile(交互式、login 方式进入bash 运行):每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件。
此文件类似于/etc/profile,也是需要需要重启才会生效,/etc/profile对所有用户生效,~/.bash_profile只对当前用户生效。
~/.bashrc(交互式 non-login 方式进入bash 运行):该文件包含专用于某个用户的bash shell的bash信息,当该用户登录时以及每次打开新的shell时,该文件被读取。每个用户都有一个.bashrc文件。
~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件。
二、异同:
1、bashrc是在系统启动后就会自动运行。profile是在用户登录后才会运行。
2、/etc/profile等中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是"父子"关系。
3、进行设置后,可运用source bashrc命令更新bashrc,也可运用source profile命令更新profile。
三、当登入系统时候获得一个shell进程时,其读取环境设定档有三步
1、首先读入的是全局环境变量设定档/etc/profile,然后根据其内容读取额外的设定的文档,如:/etc/profile.d和/etc/inputrc
2、然后根据不同使用者帐号,去其家目录读取~/.bash_profile,如果这读取不了就读取~/.bash_login,这个也读取不了才会读取~/.profile,这三个文档设定基本上是一样的,读取有优先关系
3、然后在根据用户帐号读取~/.bashrc。至于~/.profile与~/.bashrc的不区别都具有个性化定制功能。
~/.profile可以设定本用户专有的路径,环境变量等,它只能登入的时候执行一次
~/.bashrc也是某用户专有设定文档,可以设定路径,命令别名,每次shell script的执行都会使用它一次
边栏推荐
- How can the PC page call QQ for online chat?
- Leetcode simple question sharing (20)
- Regular expression integer positive integer some basic expressions
- 搜索框效果的实现【每日一题】
- Laravel5 call to undefined function OpenSSL cipher IV length() error php7 failed to open OpenSSL extension
- 最长上升子序列模型 AcWing 1012. 友好城市
- Selenium库
- Parsing of XML files
- Oracle advanced (V) schema solution
- 通过 iValueConverter 给datagrid 的背景颜色 动态赋值
猜你喜欢

2022-7-6 Leetcode27. Remove the element - I haven't done the problem for a long time. It's such an embarrassing day for double pointers

Advanced Mathematics - Chapter 8 differential calculus of multivariate functions 1

libSGM的horizontal_path_aggregation程序解读

Hands on Teaching: XML modeling

Build a secure and trusted computing platform based on Kunpeng's native security

"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?

TPG x AIDU | AI leading talent recruitment plan in progress!
![供应链供需预估-[时间序列]](/img/2c/82d118cfbcef4498998298dd3844b1.png)
供应链供需预估-[时间序列]
![[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?](/img/fb/17e029b1d955965d7e2e0f58701d91.png)
[fortress machine] what is the difference between cloud fortress machine and ordinary fortress machine?

.net core 关于redis的pipeline以及事务
随机推荐
.net core 关于redis的pipeline以及事务
Battle Atlas: 12 scenarios detailing the requirements for container safety construction
Redis 核心数据结构 & Redis 6 新特性详
Leetcode simple question sharing (20)
属性关键字Aliases,Calculated,Cardinality,ClientName
2022-7-6 Leetcode 977. Square of ordered array
【日常训练--腾讯精选50】231. 2 的幂
手里的闲钱是炒股票还是买理财产品好?
最长上升子序列模型 AcWing 1012. 友好城市
请问,PTS对数据库压测有好方案么?
CSMA/CD 载波监听多点接入/碰撞检测协议
Vmware 与主机之间传输文件
mysql导入文件出现Data truncated for column ‘xxx’ at row 1的原因
请问,redis没有消费消息,都在redis里堆着是怎么回事?用的是cerely 。
Environment configuration
LeetCode简单题分享(20)
Best practice | using Tencent cloud AI willingness to audit as the escort of telephone compliance
Excuse me, I have three partitions in Kafka, and the flinksql task has written the join operation. How can I give the join operation alone
ARM Cortex-A9,MCIMX6U7CVM08AD 处理器应用
UML sequence diagram (sequence diagram)