欢迎光临
我们一直在努力

如何在.cshrc中判断是否在loginshell中?_shell教程

建站超值云服务器,限时71元/月

当有人这么问的时候,通常要问的是 

要如何判断是否是一个 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 dont 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

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 如何在.cshrc中判断是否在loginshell中?_shell教程
分享到: 更多 (0)