bash的環境設定檔

來源:互聯網
上載者:User

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時,希望系統做的一些處理。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.