转载自:http://hi.baidu.com/shiqiang_hx/blog/item/aab77006e673217a030881cc.html
查看bash的手册页(man bash),发现以下内容:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
When a login shell exits, bash reads and executes commands from the file ~/.bash_logout, if it exists.
When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
当Bash以交互方式被调用或以带--login参数的非交互方式被调用时,它首先查找/etc/profile文件,如果文件存在就读取并执行该文件中的命令,然后依次查找“~/.bash_profile”,“~/.bash_login”和“~/.profile”这三个文件,然后执行第一个存在并且可读取的文件。使用“--noprofile”选项可以使shell在启动时不执行这些文件。
当退出一个登录Shell时,bash会查找“~/.bash_logout”文件,如果存在就读取并执行它。
当启动一个非登录交换式Shell时,bash尝试~/.bashrc文件,如果存在就读取并执行它。使用“--norc”选项可以不执行它。使用“--rcfile 文件”选项将强制bash读取并执行指定的文件来代替“~/.bashrc”。
因此,如果需要在用户一登录时就执行某些程序(如zhcon)就可以加到以上文件中。