bash
INVOCATION
A login shell is one whose first character of argument zero is a -, or one started with the --login option.
An interactive shell is one started without non-option arguments and without the -c option whose standard input and error are both connected to terminals (as determined by isatty(3)), or one started with the -i option. PS1 is set and $- includes i if bash is interactive, allowing a
shell script or a startup file to test this state.
The following paragraphs describe how bash executes its startup files. If any of the files exist but cannot be read, bash reports an error.Tildes are expanded in file names as described below under Tilde Expansion in the EXPANSION section.
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 files ~/.bash_logout and /etc/bash.bash_logout, if the files 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.
tcsh
Startup and shutdown
A login shell begins by executing commands from the system files /etc/csh.cshrc and /etc/csh.login. It then executes commands from files in the user’s home directory: first ~/.tcshrc (+) or, if ~/.tcshrc is not found, ~/.cshrc, then ~/.history (or the value of the histfile shell variable), then ~/.login, and finally ~/.cshdirs (or the value of the dirsfile shell variable) (+). The shell may read /etc/csh.login before instead of after /etc/csh.cshrc, and ~/.login before instead of after ~/.tcshrc or ~/.cshrc and ~/.history, if so compiled; see the version
shell variable. (+)
Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or ~/.cshrc on startup.
For examples of startup files, please consult http://tcshrc.sourceforge.net.
类似的可以查阅如login、/etc/profile、/etc/bashrc、/etc/csh.cshrc、/etc/csh.login等所有涉及到的配置文件的信息。同时可参考网络上其它的资料,如我在“引言”中的一些资料。
bash(sh) | |||
过程执行文件顺序 | login过程 | su过程 | su -过程 |
1 | /etc/profile | /etc/bashrc | /etc/profile |
2 | /etc/bashrc | /etc/bashrc | |
最少需配置文件 | /etc/bashrc | /etc/bashrc | /etc/bashrc |
ksh | |||
过程执行文件顺序 | login过程 | su过程 | su -过程 |
1 | /etc/profile | /etc/profile | |
2 | |||
最少需配置文件 | /etc/profile | /etc/profile | |
tcsh(csh) | |||
过程执行文件顺序 | login过程 | su过程 | su -过程 |
1 | /etc/csh.cshrc | /etc/csh.cshrc | /etc/csh.cshrc |
2 | /etc/csh.login | /etc/csh.login | |
最少需配置文件 | /etc/csh.cshrc | /etc/csh.cshrc | /etc/csh.cshrc |
Linux | ||||||||
shell | 操作 | who -m | whoami | $0 | 是否需要登录日志 | 登录日志是否存在 | 是否需要操作日志 | 操作日志是否存在 |
bash | 登录 | bash1 | bash1 | -bash | 是 | 是 | 是 | 是 |
bash | bash1 | bash1 | bash | 否 | 否 | 是 | 是 | |
su bash2 | bash1 | bash2 | bash | 是 | 是 | 是 | 是 | |
su - bash2 | bash1 | bash2 | -bash | 是 | 是 | 是 | 是 | |
ksh | 登录 | ksh1 | ksh1 | -ksh | 是 | 是 | 是 | 是 |
ksh | ksh1 | ksh1 | ksh | 否 | 否 | 是 | 否 | |
su ksh2 | ksh1 | ksh2 | ksh | 是 | 否 | 是 | 否 | |
su - ksh2 | ksh1 | ksh2 | -ksh | 是 | 是 | 是 | 是 | |
tcsh(csh) | 登录 | csh1 | csh1 | -csh | 是 | 是 | 是 | 是 |
tcsh(csh) | csh1 | csh1 | tcsh(csh) | 否 | 否 | 是 | 是 | |
su tcsh2 | csh1 | csh2 | csh | 是 | 是 | 是 | 是 | |
su - tcsh2 | csh1 | csh2 | -csh | 是 | 是 | 是 | 是 |
操作系统 | 实现方法 | SHELL | |||||
Bourne-Again Shell | POSIX Shell | Bourne Shell | Korn Shell | C Shell(csh) | C Shell(tcsh) | ||
Linux | PROMPT_COMMAND | 可以 | 无shell | 可以 | 不支持 | 不支持 | 不支持 |
trap | 未测试 | 无shell | 未测试 | 可以 | 未测试 | 未测试 | |
trap(函数) | 未测试 | 无shell | 未测试 | 未测试 | 未测试 | 未测试 | |
precmd | 不支持 | 无shell | 不支持 | 不支持 | 可以 | 可以 |