Full login sequence documentation ?

Discussion in 'Apple' started by JF Mezei, Apr 29, 2012.

  1. JF Mezei

    JF Mezei Guest

    I am trying to find an authorative list of files which are invoked when
    a unix login happens on OS-X. Once you have enterred the username and
    password, which files are invoked ?

    And when you spawn a new shell, are all those files invoked again or
    does the new shell inherit everything (environment variables etc) from
    the parent ?)

    Are there files common to all shells ? Is is bash, c-shell etc all
    dependent on different files being invoked at login ?

    Also, a newbie question: are environment variables tied to a shell or to
    a process ? For instance, if I am a bash user but invoke a script which
    is tshell, will it inherit my environment variables (such as PATH) and
    can it then modify them ?
     
    JF Mezei, Apr 29, 2012
    #1
    1. Advertising

  2. JF Mezei

    Bob Harris Guest

    In article <4f9cc801$0$9708$c3e8da3$>,
    JF Mezei <> wrote:

    > I am trying to find an authorative list of files which are invoked when
    > a unix login happens on OS-X. Once you have enterred the username and
    > password, which files are invoked ?
    >
    > And when you spawn a new shell, are all those files invoked again or
    > does the new shell inherit everything (environment variables etc) from
    > the parent ?)
    >
    > Are there files common to all shells ? Is is bash, c-shell etc all
    > dependent on different files being invoked at login ?
    >
    > Also, a newbie question: are environment variables tied to a shell or to
    > a process ? For instance, if I am a bash user but invoke a script which
    > is tshell, will it inherit my environment variables (such as PATH) and
    > can it then modify them ?


    Generally, a new shell session starts with the program 'login'
    which establishes the user/group and initial environment
    variables, then it exec's the user's shell.

    The shell's man page will tell you what initialization files are
    invoked. The default Mac OS X shell is bash (see man bash).

    bash on login invokes /etc/profile. On Mac OS X /etc/profile
    invokes /usr/libexec/path_helper which looks for /etc/paths.d and
    /etc/manpaths.d directory entries. /etc/profile will then invoke
    /etc/bashrc

    Next bash will invoke one of the following (first found in the
    following order): ~/.bash_profile, ~/.bash_login, or ~/.profile.
    Since you create one of these (they do not exist by default), what
    these initialization files invoke is totally up to you.

    If you create a subshell, then bash will invoke ~/.bashrc, and the
    subshell inherits all environment variables and exported shell
    functions.

    The separation of .bash_proifle from .bashrc allows you to create
    a lighter weight .bashrc to speed up subshell creation by
    separating environment variable setup and tasks you want to just
    once per login from operations that need to be done each time a
    sub-shell is created.

    One thing some users do, it to "source ~/.bashrc" as part of their
    ~/.bash_profile.

    And some users do now worry about subshell creation performance
    (either they do not do it all that often or their system is
    sufficiently fast that doing the .bash_profile and .bashrc work
    each time is not an issue. These users put everything in .bashrc,
    and then have just one command in their .bash_profile "source
    ~/.bashrc"

    You will want to read the man page for your shell. The section
    you want in "man bash" is "INVOCATION".
     
    Bob Harris, Apr 30, 2012
    #2
    1. Advertising

  3. JF Mezei

    JF Mezei Guest

    Bob Harris wrote:

    > The shell's man page will tell you what initialization files are
    > invoked. The default Mac OS X shell is bash (see man bash).


    many many thanks. So if I want to add system wide stuff and aliases, I
    should add it to /etc/profile ? Or is that file likely be overwritten by
    any software upgrade ?

    If a user has a different shell, does this mean that /etc/profile
    doesn't necessarily get invoked and there is a totally different chain
    of files that are invoked ?
     
    JF Mezei, Apr 30, 2012
    #3
  4. JF Mezei <> wrote:

    > many many thanks. So if I want to add system wide stuff and aliases, I
    > should add it to /etc/profile ? Or is that file likely be overwritten by
    > any software upgrade ?


    > If a user has a different shell, does this mean that /etc/profile
    > doesn't necessarily get invoked and there is a totally different chain
    > of files that are invoked ?


    I think you would have to read the man pages for each shell offered, I don't
    think /etc/profile is considered universal.

    What I do think that is common is, the stuff in the user home directory is
    the last placed checked.

    In many svr4 systems, there used to be /etc/skel which was a directory to
    drop in the custom login and profiles for that box/machine. When a user was
    created, you usually dropped in copies from there to the home.

    Since the users home directory is the last placed checked for customized
    settings, it sort of makes more sense to drop in the profile/login/bashrc or
    whatever else the desired shell uses there, than to modify the files in
    /etc.

    Although you can edit the /etc files to your hearts content, it's just one
    of those "best practices" kind of thing.

    -bruce
     
    Bruce Esquibel, Apr 30, 2012
    #4
  5. JF Mezei

    Paul Sture Guest

    On Sun, 29 Apr 2012 19:50:57 -0400, Bob Harris wrote:

    > If you create a subshell, then bash will invoke ~/.bashrc, and the
    > subshell inherits all environment variables and exported shell
    > functions.
    >
    > The separation of .bash_proifle from .bashrc allows you to create a
    > lighter weight .bashrc to speed up subshell creation by separating
    > environment variable setup and tasks you want to just once per login
    > from operations that need to be done each time a sub-shell is created.
    >
    > One thing some users do, it to "source ~/.bashrc" as part of their
    > ~/.bash_profile.


    Thanks Bob. Useful info that I didn't know before.

    --
    Paul Sture
     
    Paul Sture, Apr 30, 2012
    #5
  6. In article <4f9e2363$0$31016$c3e8da3$>,
    JF Mezei <> wrote:

    > Bob Harris wrote:
    >
    > > The shell's man page will tell you what initialization files are
    > > invoked. The default Mac OS X shell is bash (see man bash).

    >
    > many many thanks. So if I want to add system wide stuff and aliases, I
    > should add it to /etc/profile ? Or is that file likely be overwritten by
    > any software upgrade ?
    >
    > If a user has a different shell, does this mean that /etc/profile
    > doesn't necessarily get invoked and there is a totally different chain
    > of files that are invoked ?


    One thing to remember about all this stuff about shells is that it only
    applies to Terminal sessions, not normal Mac GUI logins. The latter
    don't involve the Unix shell at all.

    --
    Barry Margolin,
    Arlington, MA
    *** PLEASE post questions in newsgroups, not directly to me ***
     
    Barry Margolin, Apr 30, 2012
    #6
  7. JF Mezei

    Bob Harris Guest

    In article <4f9e2363$0$31016$c3e8da3$>,
    JF Mezei <> wrote:

    > Bob Harris wrote:
    >
    > > The shell's man page will tell you what initialization files are
    > > invoked. The default Mac OS X shell is bash (see man bash).

    >
    > many many thanks. So if I want to add system wide stuff and aliases, I
    > should add it to /etc/profile ? Or is that file likely be overwritten by
    > any software upgrade ?
    >
    > If a user has a different shell, does this mean that /etc/profile
    > doesn't necessarily get invoked and there is a totally different chain
    > of files that are invoked ?


    As has been mentioned, you would need to consult each shell's man
    page, however, I think the Bourne derived shells (sh, bash, ksh
    and zsh) will invoke /etc/profile and csh/tcsh invoke
    /etc/csh.login

    As to whether it will be replaced by system updates, that is
    always a risk, and even if it is not messed with in one update,
    nothing says the next update will not play with one of the files.

    If you do decide to modify your /etc/profile and/or /etc/csh.login
    just make sure you have your own backup copies that you always
    keep current with any changes you make.

    Perhaps the best idea would be to have your own /etc/profile.local
    /etc/csh.login.local and then just add an include to global
    initialization script

    /etc/profile
    . /etc/profile.local

    /etc/csh.login
    source /etc/csh.login.local

    That way you only have to add a single line to any updated
    /etc/profile or /etc/csh.login
     
    Bob Harris, May 1, 2012
    #7
  8. JF Mezei

    Bob Harris Guest

    In article <4f9e2363$0$31016$c3e8da3$>,
    JF Mezei <> wrote:

    > Bob Harris wrote:
    >
    > > The shell's man page will tell you what initialization files are
    > > invoked. The default Mac OS X shell is bash (see man bash).

    >
    > many many thanks. So if I want to add system wide stuff and aliases, I
    > should add it to /etc/profile ? Or is that file likely be overwritten by
    > any software upgrade ?


    NOTE 1: the /etc/profile or /etc/csh.login is ONLY going to be
    invoked during the initial session startup. Subshell creation
    will not invoke them.

    NOTE 2: Not all shells support things like aliases, nor do they
    all use the same syntax for everything. Mostly you can export
    environment variables, maybe establish personalized stty settings,
    runs a very generic script that does some checking or run a
    program at session startup. But you need to check any
    personalizations at this level with every possible shell that
    might use the /etc/profile or /etc/csh.login

    If this is really just for your own use, then you might as well
    use the home directory shell initialization files. If for the
    family, sharing a system, I would still put customizations in
    their home directories. If for a department or company wide, then
    you have to very careful and test, test, test.

    > If a user has a different shell, does this mean that /etc/profile
    > doesn't necessarily get invoked and there is a totally different chain
    > of files that are invoked ?
     
    Bob Harris, May 1, 2012
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim in Alaska
    Replies:
    1
    Views:
    2,555
    Jim in Alaska
    Jun 25, 2003
  2. Michael Hobbs

    Sound on P4C800ED- any documentation?

    Michael Hobbs, Jun 13, 2004, in forum: Asus
    Replies:
    3
    Views:
    244
    Michael Hobbs
    Jun 14, 2004
  3. JPRW

    SP700 Full Documentation

    JPRW, Feb 18, 2005, in forum: Compaq
    Replies:
    0
    Views:
    371
  4. Replies:
    7
    Views:
    304
  5. Bill Anderson
    Replies:
    3
    Views:
    923
    daytripper
    Apr 5, 2011
Loading...

Share This Page