關於“.bash_profile”和“.bashrc”區別的總結
-
更新操作
- 打開terminal(終端)
- cd ~ ( 進入當前用戶的home目錄)
- open .bash_profile (打開.bash_profile文件,如果文件不存在就 創建文件:touch .bash_profile 編輯文件:open -e bash_profile)
- 直接更改彈出的.bash_profile文件內容
- command + s 保存文件,然后關閉
- 在terminal(終端)中輸入 source .bash_profile (使用剛才更新之后的內容)
-
其他
/etc/profile: 此文件為系統的每個用戶設置環境信息,當用戶第一次登錄時,該文件被執行.並從/etc/profile.d目錄的配置文件中搜集shell的設置. /etc/bashrc: 為每一個運行bash shell的用戶執行此文件.當bash shell被打開時,該文件被讀取. ~/.bash_profile: 每個用戶都可使用該文件輸入專用於自己使用的shell信息,當用戶登錄時,該文件僅僅執行一次!默認情況下,他設置一些環境變量,執行用戶的.bashrc文件. ~/.bashrc: 該文件包含專用於你的bash shell的bash信息,當登錄時以及每次打開新的shell時,該該文件被讀取. ~/.bash_logout: 當每次退出系統(退出bash shell)時,執行該文件. 另外,/etc/profile中設定的變量(全局)的可以作用於任何用戶,而~/.bashrc等中設定的變量(局部)只能繼承/etc/profile中的變量,他們是"父子"關系.
文件 范圍 觸發節點 備注 /etc/profile 全員 第一次登陸 每次更新需要source /etc/bashrc 全員 每次打開shell ~/.bash_profile 個人 第一次登陸 每次更新需要source ~/.bashrc 個人 每次打開shell ~/.bash_login 個人 每次登陸shell ~/.bash_logout 個人 每次登出shell PS:~/.bash_profile讀取~/.bashrc...