Linux 下 Bash配置檔案讀取

2022-08-21 07:45:11 字數 1213 閱讀 9295

linux安裝時可能要修改的配置檔案:/etc/profile、/etc/bashrc(ubuntu沒有這個檔案,對應地,其有/etc/bash.bashrc檔案。我用的是ubuntu系統,所以下面將一律使用/etc/bash.bashrc來敘述)、~/.bash_profile、~/.bash_login、~/.profile、~/.bashrc。

utuntu系統預設只有/etc/profile、/etc/bash.bahsrc、~/.profile、~/.bashrc這四個檔案。其他檔案可以建立。

1  /etc/profile

用於設定系統級的環境變數和啟動程式

2  ~/.profile

該檔案是乙個使用者級的設定,這個檔案同樣也可以用於配置環境變數和啟動程式,但只針對單個使用者有效

3  ~/.bashrc和/etc/bashrc(/etc/bash.bahsrc)

這個兩個檔案用於配置函式或別名,/etc/bashrc是系統級的、~/.bashrc是使用者級的,兩者分別會對所有使用者和當前使用者生效。

讀取順序:

在4個檔案中加入 echo 語句測試

切換管理員

eko@ubuntu:~$ su -

password:

here is /etc/bash.bashrc

here is /etc/profile

切換使用者

root@ubuntu:~# su - 'eko'

here is /etc/bash.bashrc

here is /etc/profile

here is /eko/.bashrc

here is /eko/.profile

可見登入式shell執行順序是:

/etc/.bashrc --> /etc/profile -->  ~/.bashrc --> ~/.profile

非登入式shell

eko@ubuntu:~$ su

password:

here is /etc/bash.bashrc

root@ubuntu:/home/eko# su 'eko'

here is /etc/bash.bashrc

here is /eko/.bashrc

/etc/bash.bashrc --> ~/.bashrc

bash配置檔案

本文主要對linux系統bash配置檔案進行比較分析。1.首先是兩個全域性的配置檔案。etc profile 此檔案為系統的每個使用者設定環境資訊,當使用者第一次登入時,該檔案被執行。並從 etc profile.d目錄的配置檔案中蒐集shell的設定.etc bash.bashrc 為每乙個執行b...

bash 配置檔案

兩類 profile類 為互動式登入的shell程序提供配置 bashrc類 為非互動式登入的shell程序提供配置 登入型別 互動式登入shell程序 直接通過某終端輸入賬號和密碼後登入開啟的shell程序 使用su命令 su username,或者 su l username 執行的切換 非互動...

bash配置檔案

bash登入型別 互動式登入shell程序 直接通過某終端輸入密碼和賬號登入開啟的shell程序 使用su username執行的登入切換 或者 su l username 命令為小寫l 非互動式登入shell程序 su unsername 執行登入切換 圖形介面下開啟的終端 執行指令碼 配置檔案型...