打開bash後,要編寫變數可以寫在 ~/.bash_profile 或 ~/.bashrc。
也許還聽過 /etc/profile
位置不同但效果相同,有想過這些順序和情境到底怎麼使用嗎?
- /etc/profile
- ~/.bash_profile
- ~/.bashrc
- ~/.bash_login
- ~/.profile
- ~/.bash_logout
// 一般順序
execute /etc/profile IF ~/.bash_profile exists THEN execute ~/.bash_profile ELSE IF ~/.bash_login exist THEN execute ~/.bash_login ELSE IF ~/.profile exist THEN execute ~/.profile END IF END IF END IF
// 互動登出
IF ~/.bash_logout exists THEN execute ~/.bash_logout END IF
//互動式非登入
IF ~/.bashrc exists THEN execute ~/.bashrc END IF
參考文章在此
Execution sequence for .bash_profile, .bashrc, .bash_login, .profile and .bash_logout
https://www.thegeekstuff.com/2008/10/execution-sequence-for-bash_profile-bashrc-bash_login-profile-and-bash_logout/