理解login shell和non-login shell
用戶交互式login的時(shí)候,就會(huì)初始化profile相關(guān)的腳本,這就是所謂的login shell。
當(dāng)在已經(jīng)存在的shell里面啟動(dòng)另外一個(gè)shell的時(shí)候,比如使用"bash"或者"su",啟動(dòng)的這個(gè)新shell就會(huì)初始化rc相關(guān) 的腳本。這個(gè)shell就稱為non-login shell。
login shell會(huì)執(zhí)行的腳本有 /etc/profile和~/.bash_profile。
non-login shell會(huì)執(zhí)行的腳本通常有/etc/bashrc (在debian/ubuntu上是/etc/bash.bashrc)和~/.bashrc。
在tty下login進(jìn)去,得到的是一個(gè)login shell。之后使用bash或者su命令得到的是non-login shell。
而在debian/ubuntu下的GNOME用terminal啟動(dòng)出來的shell是non-login shell。退出該non-login shell的話,只需要exit即可。
login shell 讀取 /etc/profile 和 ~/.bash_profile , 并且是 先讀入 profile 后讀入 .bash_profile, 2個(gè)文件必讀,
至于 bash.bashrc 和 .bashrc 則看 profile 和 .bash_profile 是否明確指定讀。