[lug] Changing paths

Tkil tkil at scrye.com
Wed Apr 5 20:02:04 MDT 2000


regarding .profile and .login and .*shrc:

1. bourne shell ran /etc/profile then $HOME/.profile for login shells,
   and i think that was about it.  but i don't know much about it, and
   it is old enough to where its behavior has almost certainly changed
   over time -- meaning that there is an issue as to what is the
   "true" bourne shell.

2. csh ran both ".login" and ".cshrc" for login shells, although i
   don't remember what order they were run in.  for non-login shells
   (e.g. running a script that used csh as its interpreter), it would
   run only .cshrc.  i remember the manual for csh (at least on sunos,
   which was the last place i used it) had a good discussion on this,
   along with hacks to deal with various combinations.

   i believe csh also introduced the ".logout" file, which would be
   run whenever any login shell exited (which often led to the need
   for ref-counting instances of login shells on the same machine,
   whee.)

   i don't recall which /etc/* files were run by csh by default;
   possibly "/etc/cshrc" and "/etc/login" under similar rules as the
   files in your home directory.

   i don't have a "man csh" on my system, but "man tcsh" gives:

|    Startup and shutdown
|        A login shell begins by executing commands from the system
|        files /etc/csh.cshrc and /etc/csh.login.  It then executes
|        commands  from  files  in the user's home directory: first
|        ~/.tcshrc (+) or, if ~/.tcshrc  is  not  found,  ~/.cshrc,
|        then  ~/.history (or the value of the histfile shell vari-
|        able), then ~/.login, and finally ~/.cshdirs (or the value
|        of  the  dirsfile shell variable) (+).  The shell may read
|        /etc/csh.login before instead of after /etc/csh.cshrc, and
|        ~/.login before instead of after ~/.tcshrc or ~/.cshrc and
|        ~/.history, if so compiled; see the  version  shell  vari-
|        able. (+)
|
|        Non-login shells read only /etc/csh.cshrc and ~/.tcshrc or
|        ~/.cshrc on startup.
|
|        Commands like stty(1) and tset(1), which need be run  only
|        once  per login, usually go in one's ~/.login file.  Users
|        who need to use the same set of files with both csh(1) and
|        tcsh  can  have only a ~/.cshrc which checks for the exis-
|        tence of the tcsh shell variable (q.v.) before using tcsh-
|        specific  commands,  or  can  have  both  a ~/.cshrc and a
|        ~/.tcshrc  which  sources  (see   the   builtin   command)
|        ~/.cshrc.   The  rest  of  this manual uses '~/.tcshrc' to
|        mean '~/.tcshrc or, if ~/.tcshrc is not found,  ~/.cshrc'.
|
|        In the normal case, the shell begins reading commands from
|        the terminal, prompting with '> '.  (Processing  of  argu-
|        ments and the use of the shell to process files containing
|        command scripts are described later.)  The  shell  repeat-
|        edly  reads a line of command input, breaks it into words,
|        places it on the command history list, parses it and  exe-
|        cutes each command in the line.
|
|        One  can log out by typing '^D' on an empty line, 'logout'
|        or 'login' or via the shell's  autologout  mechanism  (see
|        the autologout shell variable).  When a login shell termi-
|        nates it sets the logout shell  variable  to  'normal'  or
|        'automatic'  as  appropriate,  then executes commands from
|        the files /etc/csh.logout and  ~/.logout.  The  shell  may
|        drop  DTR  on logout if so compiled; see the version shell
|        variable.
|
|        The names of the system login and logout files  vary  from
|        system  to  system for compatibility with different csh(1)
|        variants; see FILES.
|
|        [...]
|
| Files
|        /etc/csh.cshrc  Read  first  by  every  shell.   ConvexOS,
|                        Stellix and Intel use /etc/cshrc and NeXTs
|                        use  /etc/cshrc.std.  A/UX, AMIX, Cray and
|                        IRIX have no  equivalent  in  csh(1),  but
|                        read  this  file  in tcsh anyway.  Solaris
|                        2.x does not  have  it  either,  but  tcsh
|                        reads /etc/.cshrc. (+)
|        /etc/csh.login  Read by login shells after /etc/csh.cshrc.
|                        ConvexOS,   Stellix    and    Intel    use
|                        /etc/login,   NeXTs   use  /etc/login.std,
|                        Solaris 2.x  uses  /etc/.login  and  A/UX,
|                        AMIX, Cray and IRIX use /etc/cshrc.
|        ~/.tcshrc (+)   Read  by  every shell after /etc/csh.cshrc
|
|                        or its equivalent.
|        ~/.cshrc        Read by every shell, if ~/.tcshrc  doesn't
|                        exist, after /etc/csh.cshrc or its equiva-
|                        lent.  This  manual  uses  '~/.tcshrc'  to
|                        mean  '~/.tcshrc  or,  if ~/.tcshrc is not
|                        found, ~/.cshrc'.
|        ~/.history      Read by login shells  after  ~/.tcshrc  if
|                        savehist is set, but see also histfile.
|        ~/.login        Read  by  login  shells after ~/.tcshrc or
|                        ~/.history.  The shell may be compiled  to
|                        read  ~/.login  before  instead  of  after
|                        ~/.tcshrc and ~/.history; see the  version
|                        shell variable.
|        ~/.cshdirs (+)  Read  by  login  shells  after ~/.login if
|                        savedirs is set, but see also dirsfile.
|        /etc/csh.logout Read by login shells at logout.  ConvexOS,
|                        Stellix  and  Intel  use  /etc/logout  and
|                        NeXTs use  /etc/logout.std.   A/UX,  AMIX,
|                        Cray   and  IRIX  have  no  equivalent  in
|                        csh(1), but read this file in tcsh anyway.
|                        Solaris  2.x  does not have it either, but
|                        tcsh reads /etc/.cshrc. (+)
|        ~/.logout       Read  by  login  shells  at  logout  after
|                        /etc/csh.logout or its equivalent.



3. ksh runs ".profile" only for login shells.  if the environment
   variable "ENV" is set, it will be executed for every shell,
   including scripts.  again, i'm not sure about it's system-wide
   behavior.

4. bash normally acts like the bourne shell, but it picked up many
   habits from all over the place.  a quick review of the info pages
   for bash seems to indicate the following files... ah, here we go
   (from the info node "(bash.info.gz)Bash Startup Files"):

|   When and how Bash executes startup files.
|
|      For Login shells (subject to the -noprofile option):
|
|          On logging in:
|             If `/etc/profile' exists, then source it.
|
|             If `~/.bash_profile' exists, then source it,
|                else if `~/.bash_login' exists, then source it,
|                   else if `~/.profile' exists, then source it.
|
|          On logging out:
|             If `~/.bash_logout' exists, source it.
|
|      For non-login interactive shells (subject to the -norc and
|      -rcfile options):
|          On starting up:
|             If `~/.bashrc' exists, then source it.
|
|      For non-interactive shells:
|          On starting up:
|             If the environment variable `ENV' is non-null, expand the
|             variable and source the file named by the value.  If Bash
|             is not started in Posix mode, it looks for `BASH_ENV'
|             before `ENV'.

   which answers that question handily.

most of the variant shells (tcsh, zsh) follow the csh rules, but tend
to add a specific ".${SHELL_BASENAME}rc" file: .zshrc, .tcshrc, etc.

does this answer the question?  i apologize for being so wishy-washy,
but the answer really does tend to be:  read the docs for *your*
version of *your* shell.

good luck,
t.





More information about the LUG mailing list