[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bash in xterm under x*

joost@pc47.mpn.cp.philips.com writes:

> > Make a symlink between bashrc and bash_profile.  Anything else is just
> > icky:->

Actually, I thought that _profile was icky too, so I link .bash_login
to .bashrc (login made more sense to me), and I don't have a
.bash_profile.  Bash will DTRT.

> Hmm, AFAIK, either .bash_profile or .bashrc gets sourced at the startup of
> a shell.  But .bash_profile is sourced when bash is started as a (new)
> login shell and .bashrc only when a subshell is spawned.
> I put this in my .bash_profile:
>     if [ -f $HOME/.bashrc ]; then
>         . $HOME/.bashrc
>     fi

You're right that you want as little as possible to be re-run in
.bashrc each time it's sourced, but as I understand it, this solution
won't necessarily get what you want.  The problem is that not
everything calls bash as a login shell when it should (X maybe?).

To make sure that I don't have to depend on anyone doing the right
thing, but still never re-execute code that should only run once, I
handle everything in my .bashrc (which is symlinked from my
.bash_login), and I do this to make sure that I only do "one-time"
stuff once (don't know if this is perfect, but it works for me):

  # .bashrc

  # Only do things here at the top that *cannot* be handled by
  # BASH_INITIALIZED.  As far as I can tell, PATH is the only thing
  # because: Bash's PATH handling is *screwed*.  If you launch a
  # --login shell from another process PATH is cleared to default, but
  # *only* PATH, so there's no way (that I know of) to detect that it
  # happened.

  if ! echo ${PATH} | fgrep ${HOME}/.bin > /dev/null 2>&1 
    # Path hasn't been set up properly.  Set it.
    export PATH=${HOME}/.bin:${PATH}

  if [ ${PS1:-UNSET} = UNSET ]
    # setup the prompt here (my setup of funky dynamic titlebar
    # prompts for xterms omitted)...
    export PS1='\n\u@\h:\w\n\!\$ '

  if [ x"${BASH_INITIALIZED}" != "xYes" ]

    # Do all of your one-time only stuff here.  You can use
    # $INTERACTIVE_SHELL to determine if you're in an interactive
    # shell.

> beginning of my .xsession (which should be linked to .xinitrc AFAIC):
>     # source login actions and definitions for this xsession:
>     if [ -f $HOME/.bashrc ]; then
>         . $HOME/.bashrc
>     fi

Right, this is also a good idea.  I do this too.

Rob Browning <rlb@cs.utexas.edu> PGP=E80E0D04F521A094 532B97F5D64E3930

Reply to: