bash的環境設定檔
1. login shell 和 non-login shelllogin shell 和 non-login shell 區別在於登入 login。 login shell : 通過完整的登入流程, 舉例:通過tty1-tty6 登入,需要輸入使用者的帳號和密碼,此時取得的 bash 就是 login shell。 non-login shell : 取得bash介面的方法不需要重複登陸,比如下面兩種方法: 1, 以 X Window登入linux後, 再以 X 的圖形介面啟動終端機,此時這個終端沒有再次輸入使用者名稱和密碼,這個bash環境為 non-login shell 2, 在原bash下再次執行bash,同樣沒有輸入使用者名稱和密碼,此時第二個bash,子進程,為non-login shell。
login shell 與 non-login shell 讀取的設定檔不一樣。
2. login shelllogin shell 讀取兩個設定檔: 1. /etc/profile 2. ~/.bash_profile,或 ~/.bash_login, 或 ~/.profile。
2.1 /etc/profile這個配置為使用者整體的配置,最好不要修改這個檔案,除非給所有使用者佈建整體環境。 這個檔案設定的變數主要有: PATH : 跟據使用者佈建 USER: 使用者名稱 HOSTNAME: 主機名稱 HISTSIZE : 曆史命令條數 該檔案會調用下面檔案: /etc/inputrc : 主要設定bash 熱鍵,[Tab] 有沒有聲音等。 /etc/profile.d/*.sh : 主要規定bash介面的顏色,語系等,如果要給所有使用者佈建組態變數時,在/etc/profile.d/目錄下,建 .sh 檔案。 /etc/sysconfig/i18n: 該檔案由/etc/profile.d/lang.sh 檔案調用, 設定bash預設使用哪種語系。
2.2 ~/.bash_profilebash讀取完整體環境變數/etc/profile 後會讀取個人使用者配置。主要有下面三個檔案: 1. ~/.bash_profile 2. ~/.bash_login 3. ~/.profile 只會讀取其中一個檔案,順序為上面的順序,只要前面檔案存在,後面則不再讀取。
$ vim ~/.bash_profile # .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/binexport PATHunset USERNAME
該檔案會讀取 ~/.bashrc 檔案。 source和. 為讀入設定檔。
]$ source .bashrc ]$ . .bashrc
3. non-login shellnon-login shell 會讀取 ~/.bashrc 查看該檔案:
# .bashrc# User specific aliases and functions# Source global definitionsif [ -f /etc/bashrc ]; then . /etc/bashrcfialias rm='rm -i'
會讀取 /etc/bashrc 該檔案會設定: 跟據UID設定umask PS1: 提示符 調用/etc/profile.d/*.sh
4. 其他配置/etc/man.config 配置手冊的目錄,man 命令 ~/.bash_history 記錄bash的曆史命令 ~/.bash_logout 登出bash時,希望系統做的一些處理。