當有人這麼問的時候,通常要問的是
要如何判斷是否是一個 interactive shell? 或是問要如何判斷是否是 最上層的 shell ?
若你是要問 "是否在 login shell 中"(註:就是在做完 .cshrc 後,會 再去做 .login),那麼你也許用 "ps" 和 "$$" 隨便弄一弄,就能知道了 。因為通常 login shells 的名字在 "ps" 看起來都是由 '-' 做開頭的。 如果你是真的對另外兩個問題感興趣,那麼這裡有個方法可以讓你在 .cshrc 中判斷。
if (! $?CSHLEVEL) then # # This is a "top-level" shell, # perhaps a login shell, perhaps a shell started up by # 'rsh machine some-command' # This is where we should set PATH and anything else we # want to apply to every one of our shells. # setenv CSHLEVEL 0 set home = ~username # just to be sure source ~/.env # environment stuff we always want else # # This shell is a child of one of our other shells so # we don't need to set all the environment variables again. # set tmp = $CSHLEVEL @ tmp++ setenv CSHLEVEL $tmp endif # Exit from .cshrc if not interactive, e.g. under rsh if (! $?prompt) exit # Here we could set the prompt or aliases that would be useful # for interactive shells only. source ~/.aliases