Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

Unix - Frequently Asked Questions (2/7) [Frequent posting]
Section - How do I tell inside .cshrc if I'm a login shell?

( Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Airports ]


Top Document: Unix - Frequently Asked Questions (2/7) [Frequent posting]
Previous Document: How do I redirect stdout and stderr separately in csh?
Next Document: How do I construct a ... matches all files except "." and ".." ?
See reader questions & answers on this topic! - Help others by sharing your knowledge

2.10) How do I tell inside .cshrc if I'm a login shell?

      When people ask this, they usually mean either

        How can I tell if it's an interactive shell?  or
        How can I tell if it's a top-level shell?

      You could perhaps determine if your shell truly is a login shell
      (i.e. is going to source ".login" after it is done with ".cshrc")
      by fooling around with "ps" and "$$".  Login shells generally
      have names that begin with a '-'.  If you're really interested in
      the other two questions, here's one way you can organize your
      .cshrc to find out.

        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

User Contributions:

Comment about this article, ask questions, or add new information about this topic:

CAPTCHA




Top Document: Unix - Frequently Asked Questions (2/7) [Frequent posting]
Previous Document: How do I redirect stdout and stderr separately in csh?
Next Document: How do I construct a ... matches all files except "." and ".." ?

Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
tmatimar@isgtec.com (Ted Timar)





Last Update March 27 2014 @ 02:12 PM