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