如何在.cshrc中判断是否在loginshell中?
ReadyGo!技术成就梦想
网络搜索
efish
2008-2-24 2:50:17
当有人这么问的时候,通常要问的是
要如何判断是否是一个 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
要如何判断是否是一个 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
-
相关文章
在Bourneshellscript里要怎么找出最后一个参数?
在Bourneshellscript里要怎么找出最后一个参数?
如何让setuid的shellscript可以使用?
如何让setuid的shellscript可以使用?
shell要如何分类呢?
shell要如何分类呢?
Shell介绍
Shell介绍
Linux程式设计-11.ShellScript(bash)--(1)简介
Linux程式设计-11.ShellScript(bash)--(1)简介
Linux程式设计-11.ShellScript(bash)--(2)教学例
Linux程式设计-11.ShellScript(bash)--(2)教学例
Linux程式设计-11.ShellScript(bash)--(3)用於自动备…
Linux程式设计-11.ShellScript(bash)--(3)用於自动备份的ShellScript
Linux程式设计-11.ShellScript(bash)--(4)档案系统检…
Linux程式设计-11.ShellScript(bash)--(4)档案系统检查
Linux程式设计-11.ShellScript(bash)--(5)控制圈for
Linux程式设计-11.ShellScript(bash)--(5)控制圈for
Linux程式设计-11.ShellScript(bash)--(6)流程控制c…
Linux程式设计-11.ShellScript(bash)--(6)流程控制case
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的ReadyGo.com.cn
