Stock bash startup varies depending on whether your shell is a login shell or not, whether it is interactive or not and various other things which most of the time we don't care about. My startup scripts simplify the process. If we have a tty all scripts are sourced. If we don't they aren't. My .bashrc sources .bash_profile to ensure that everything is always set up regardless of how bash is started, as which script is sourced at startup depends on the type of shell. See INVOCATION in the bash manpage for more details.
My .bash_profile looks for files in $PROFILE_HOME/.profile.d (and its subdirectories) and sources anything whose name ends in .bashrc. This allows the creation of separate scripts for different functions and is easier to manage than having a single giant script to wade through.
If PROFILE_HOME expands to an empty string it is replaced by ~, ie your home directory. See the become command for more details.
Various globbing and locale options are set such that scripts are read in alphabetical order with UPPERCASE files sorting before lowercase ones. Thus if ~/.profile.d contains the files wibble.bashrc, WOBBLE.bashrc, flibble.bashrc and flirble.bashrc they will, by default, be parsed in the following order:
If present, OS.bashrc, PATH.bashrc and BECOME.bashrc will be sourced first.
It is possible to override the order in which the remaining scripts are sourced by adding one or more lines at the top of a file. The format is as follows:
.bashrc [ .bashrc ...]
The file containing profile-required line(s) will be sourced after the named file(s). For example, to ensure that WOBBLE.bashrc was sourced after the other files listed above you could add the following line to the top of WOBBLE.bashrc:
# profile-required: flibble.bashrc flirble.bashrc wibble.bashrc
The tsort command is used to order the files. If it fails they will be sourced in the standard order.
My .bash_profile will not do anything if there is no tty on stdin and the first character of argument zero is not -. It can be forced to source scripts by calling it with the force argument:
. ~/.bash_profile force