今天想 在 .bashrc 中配置一段自動啟動 ssh-agent 的腳本,結果總是沒有自動運行;才發現我的 bashrc 腳本沒有自動 加載
后來才發現是這次裝的深度系統(deepin)默認沒有 ~.PRofile
腳本, 去看看之前的Ubuntu系統里面都默認是有這個腳本的,而 ~.bashrc
腳本則是通過 .profile 來加載的
1. linux系統加載bash配置腳本的順序如果新建一個用戶, 在其 $HOME 目錄下會自動創建 .profile 腳本嗎?
.bashrc 文件本身在 *nix 系統下就不會自動加載,一般都是通過 .profile 間接加載的
一般,系統會按下面的順序加載
/etc/profile~/.bash_profile~/.bash_login~/.profile
如果你的.bashrc
沒有自動加載,就新建 ~/.profile
# ~/.profile: executed by Bourne-compatible login shells.if [ "$BASH" ]; then if [ -f ~/.bashrc ]; then . ~/.bashrc fi fimesg n
當然如果, 已經有了
.bash_profile
or.bash_login
, 那么這個.profile
文件也不會被加載。 總之,是把 此段代碼寫到 已經存在的 最先被加載到的那個配置中。
refer to :
http://askubuntu.com/questions/260682/bashrc-not-autosourced-in-12-04-ltshttp://apple.stackexchange.com/questions/12993/why-doesnt-bashrc-run-automatically
2. Difference Between .bashrc & .bash_profile.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells.
當你直接在機器login界面登陸、使用ssh登陸或者su切換用戶登陸時,.bash_profile 會被調用來初始化shell環境Note:.bash_profile文件默認調用.bashrc文件
你已經登陸系統后,每打開一個新的Terminal時,.bashrc 都會被再次調用。
若要配置環境變量之類,最保險是寫在 .bashrc 文件中。因為不管是登陸還是不登陸,該文件總會被調用
refer to :
http://upgirl.blog.51cto.com/3744514/1140176
新聞熱點
疑難解答