For Bash ``` +----------------+-----------+-----------+------+ | |Interactive|Interactive|Script| | |login |non-login | | +----------------+-----------+-----------+------+ |/etc/profile | A | | | +----------------+-----------+-----------+------+ |/etc/bash.bashrc| | A | | +----------------+-----------+-----------+------+ |~/.bashrc | | B | | +----------------+-----------+-----------+------+ |~/.bash_profile | B1 | | | +----------------+-----------+-----------+------+ |~/.bash_login | B2 | | | +----------------+-----------+-----------+------+ |~/.profile | B3 | | | +----------------+-----------+-----------+------+ |BASH_ENV | | | A | +----------------+-----------+-----------+------+ | | | | | +----------------+-----------+-----------+------+ | | | | | +----------------+-----------+-----------+------+ |~/.bash_logout | C | | | +----------------+-----------+-----------+------+ ``` Bash File 的详细流程 {{:bashstartupfiles1.png?400|}} Zsh For zsh: [Note that zsh seems to read ~/.profile as well, if ~/.zshrc is not present.] ``` +----------------+-----------+-----------+------+ | |Interactive|Interactive|Script| | |login |non-login | | +----------------+-----------+-----------+------+ |/etc/zshenv | A | A | A | +----------------+-----------+-----------+------+ |~/.zshenv | B | B | B | +----------------+-----------+-----------+------+ |/etc/zprofile | C | | | +----------------+-----------+-----------+------+ |~/.zprofile | D | | | +----------------+-----------+-----------+------+ |/etc/zshrc | E | C | | +----------------+-----------+-----------+------+ |~/.zshrc | F | D | | +----------------+-----------+-----------+------+ |/etc/zlogin | G | | | +----------------+-----------+-----------+------+ |~/.zlogin | H | | | +----------------+-----------+-----------+------+ | | | | | +----------------+-----------+-----------+------+ | | | | | +----------------+-----------+-----------+------+ |~/.zlogout | I | | | +----------------+-----------+-----------+------+ |/etc/zlogout | J | | | +----------------+-----------+-----------+------+ ``` 总结   For bash, put stuff in ~/.bashrc, and make ~/.bash_profile source it.   For zsh, put stuff in ~/.zshrc, which is always executed. 参考链接: 1. ["Consign them to dust and damp by way of preserving them" Zsh/Bash startup files loading order (.bashrc, .zshrc etc.)](https://shreevatsa.wordpress.com/2008/03/30/zshbash-startup-files-loading-order-bashrc-zshrc-etc/)