[英]Differences, uses and similarities between .bashrc .bash_profile and /etc/profile
我使用幾種版本的linux(CentOS,SuSe和Ubuntu),每次需要弄亂PATH時,都會遇到一個問題,即不知道默認情況下定義的位置。
據我所知~/.bashrc
, ~/.bash_profile
和/etc/profile
是等式的一部分。 有誰知道這些文件的用途和區別?
對於Bash,它們的工作方式如下。 讀取適當的列。 執行A,然后執行B,然后執行C,依此類推。B1,B2,B3表示僅執行找到的那些文件中的第一個。
+----------------+-----------+-----------+------+
| |Interactive|Interactive|Script|
| |login |non-login | |
+----------------+-----------+-----------+------+
|/etc/profile | A | | |
+----------------+-----------+-----------+------+
|/etc/bash.bashrc| | A | |
+----------------+-----------+-----------+------+
|~/.bashrc | | B | |
+----------------+-----------+-----------+------+
|~/.bash_profile | B1 | | |
+----------------+-----------+-----------+------+
|~/.bash_login | B2 | | |
+----------------+-----------+-----------+------+
|~/.profile | B3 | | |
+----------------+-----------+-----------+------+
|BASH_ENV | | | A |
+----------------+-----------+-----------+------+
| | | | |
+----------------+-----------+-----------+------+
| | | | |
+----------------+-----------+-----------+------+
|~/.bash_logout | C | | |
+----------------+-----------+-----------+------+
更詳細的信息是來自http://www.solipsys.co.uk/new/BashInitialisationFiles.html的出色流程圖:
.bashrc
為特定用戶定義外殼環境。 它在每次bash啟動時運行,無論它以何種模式運行,例如交互式shell,從ssh user@host cat /etc/hosts
類的遠程調用甚至是純shell腳本運行。
.bash_profile
是每個用戶的登錄配置文件。 它在您登錄時運行一次,並執行用戶與系統交互時所需的操作,例如當日消息或新消息列表。
/ etc / profile是系統范圍的登錄配置文件腳本。 當您登錄時,它也會運行一次,但會在所有用戶特定於用戶的.bash_profile
之前運行
對於類似PATH變量的環境,.bashrc或/etc/bash.bashrc是一個好地方,因此您不必擔心登錄或非登錄Shell。
該頁面有一些詳細信息: http : //stefaanlippens.net/bashrc_and_others
/etc/profile
是登錄外殼程序的全局配置(是否為交互式), ~/.bash_profile
是登錄外殼程序的按用戶配置,而~/.bashrc
是交互式非登錄外殼程序的配置。
來自man bash
:
調用
[...]
當bash作為交互式登錄shell或具有--login選項的非交互式shell被調用時,它首先從文件/ etc / profile中讀取並執行命令(如果該文件存在)。 讀取該文件后,它將按該順序查找〜/ .bash_profile,〜/ .bash_login和〜/ .profile,並從存在的且可讀的第一個命令中讀取並執行命令。 啟動外殼程序時,可以使用--noprofile選項禁止此行為。
[...]
當啟動非登錄外殼的交互式外殼時,bash從〜/ .bashrc讀取並執行命令(如果該文件存在)。 使用--norc選項可以禁止這種情況。 --rcfile file選項將強制bash從文件而不是〜/ .bashrc中讀取並執行命令。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.