当前位置:网站首页>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的执行都会使用它一次
边栏推荐
- 手把手教会:XML建模
- 2022-7-6 Leetcode 977. Square of ordered array
- libSGM的horizontal_path_aggregation程序解读
- 【立体匹配论文阅读】【三】INTS
- Battle Atlas: 12 scenarios detailing the requirements for container safety construction
- wpf dataGrid 实现单行某个数据变化 ui 界面随之响应
- requires php ~7.1 -> your PHP version (7.0.18) does not satisfy that requirement
- Sliding rail stepping motor commissioning (national ocean vehicle competition) (STM32 master control)
- Common response status codes
- 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
猜你喜欢

UML 状态图

Leecode3. Longest substring without repeated characters

gvim【三】【_vimrc配置】

Reverse non return to zero code, Manchester code and differential Manchester code of common digital signal coding

Advanced Mathematics - Chapter 8 differential calculus of multivariate functions 1

SAKT方法部分介绍

Flask session forged hctf admin

最长上升子序列模型 AcWing 1012. 友好城市

js 获取当前时间 年月日,uniapp定位 小程序打开地图选择地点

LeetCode简单题分享(20)
随机推荐
[daily training] 648 Word replacement
PostgreSQL array type, each splice
Oracle advanced (V) schema solution
Help tenants
Codes de non - retour à zéro inversés, codes Manchester et codes Manchester différentiels couramment utilisés pour le codage des signaux numériques
Realization of search box effect [daily question]
"Song of ice and fire" in the eleventh issue of "open source Roundtable" -- how to balance the natural contradiction between open source and security?
mysql导入文件出现Data truncated for column ‘xxx’ at row 1的原因
Laravel5 call to undefined function openssl cipher iv length() 报错 PHP7开启OpenSSL扩展失败
[high frequency interview questions] difficulty 2.5/5, simple combination of DFS trie template level application questions
c#利用 TCP 协议建立连接
Huawei image address
Advanced Mathematics - Chapter 8 differential calculus of multivariate functions 1
参数关键字Final,Flags,Internal,映射关键字Internal
docker部署oracle
Environment configuration
Excuse me, why is it that there are no consumption messages in redis and they are all piled up in redis? Cerely is used.
Laravel Form-builder使用
Did login metamask
AI talent cultivation new ideas, this live broadcast has what you care about