Re: Difference between .bashrc and .bash_profile?

From: Floyd L. Davidson (floyd_at_barrow.com)
Date: 01/29/05

  • Next message: Ulf Meinhardt: "How to create a formatted timestamp and use it in filename in a script?"
    Date: Fri, 28 Jan 2005 14:41:26 -0900
    
    

    downup@turtle.com (Viet Nguyen) wrote:
    >What's the difference between the two bash start files ?

    (Read the man page for bash, under the section on INVOCATION,
    or none of this makes half as much sense as it should.)

       1) The profile file (which ever of the three files
          is used) is read only by login shells.

    It should have things that initialize the terminal or otherwise
    need be done one time only when a user does a login. Typically,
    initializing a terminal is slow. Hence one common example might
    be "stty ^H erase". Another example is "PATH=~/bin:$PATH",
    which is quick and easy, but if done for every subshell adds
    unnecessary search elements to the PATH variable if subshells
    are layers deep.

       2) The rc file is read by every interactive subshell
          (and not by login shells).

    It should have things that are needed by for interactive use,
    but are excess baggage for non-interactive subshells. Typically
    that would be the definitions of aliases.

       3) $ENV or $/BASH/_ENV specifies a file read by
          non-interactive subshells, i.e., scripts.

    This file can have functions, aliases, or variables that are
    unneeded in an interactive shell.

    The basic idea, which made obvious sense back when the
    functionality was first added to /bash/, is to speed up shell
    initialization by compartmentalizing it. When a 10Mb disk was
    the norm, and it was *SLOW*, the time spent slowly reading in a
    large _~/.profile_ for every single shell invocation, the way
    /sh/ did, was significant and a very noticeable bottleneck.

    Today of course not only is the disk file many many times faster
    itself, but we have the kernel cashing oft used disk files and
    it can be assumed that for a typical /bash/ invocation all of
    the init files have already been cached in RAM, and no disk
    activity is even done.

    -- 
    Floyd L. Davidson           <http://web.newsguy.com/floyd_davidson>
    Ukpeagvik (Barrow, Alaska)                         floyd@barrow.com
    

  • Next message: Ulf Meinhardt: "How to create a formatted timestamp and use it in filename in a script?"

    Relevant Pages

    • Re: Difference between .bashrc and .bash_profile?
      ... (Read the man page for bash, under the section on INVOCATION, ... The rc file is read by every interactive subshell ... Today of course not only is the disk file many many times faster ...
      (comp.unix.shell)
    • Re: Difference between .bashrc and .bash_profile?
      ... (Read the man page for bash, under the section on INVOCATION, ... The rc file is read by every interactive subshell ... Today of course not only is the disk file many many times faster ...
      (comp.os.linux.misc)
    • Re: leaked on lvscan invocation
      ... File descriptor 4 leaked on lvscan invocation. ... | get closed and messages are issued warning about the leak. ... It's warning of a possible bug in *bash*, ...
      (uk.comp.os.linux)
    • Re: PS1 value in shells
      ... "posix mode + historical startup" of bash: INVOCATION in bash. ...
      (comp.unix.shell)