For the bash
shell PATH
global (non-terminal) environment variables, I follow the convention used in my Ubuntu VM installation - other shells will vary:
Caveat: The whole shell start-up sequence, which .bashrc
, .profile
, etc. files are sourced in which order?, when do I have to re-login to get visibility to newly defined variables, aliases, etc?, what's the difference between a login, interactive, and non-interactive shell - I do use cron
?, and why when I do a . ~/.bashrc
is my stupid PATH
variable growing longer and longer? are the key questions that come to mind when I'm thinking of my PATH
variable.
In fact, I just completely re-wrote my entire bash startup file set taking ideas from the Ubuntu and cygwin skeleton files, and here are some of my in sites:
- Export the
PATH
and other global environment variables (i.e.LD_LIBRARY_PATH
) variables in the.profile
; - Use logic in
~/.profile
to source$HOME/.bashrc
if it exists; - Fence execution of the
~/.bashrc
with a test for interactive execution, exit otherwise; - Put all the aliases,
shopt
's, prompt setup, history control, terminal setup, function definition, etc. (interactive related setup) in the part of~/.bashrc
that is protected to only run in interactive mode; - Get rid of the other bash startup files, because their existence determines whether the control path through
.profile
and.bashrc
works as expected. That is, unless there are specific requirements to do otherwise, remove~/.bash_profile
&~/.bash_login
; - When I'm at the bash prompt, and I need to update some default setup, I edit my
~/.bashrc
file, then simply source it with a. ~/.bashrc
to get those changes in my current shell. - When I make a change to an environment variable like
PATH
, I need to modify and source my~/.profile
; - I put my calls to fink, port, and brew specific setups in
.profile
.
That's my 2 cents on this topic.