System Wide Bash Login Script

Graham Allan allan at
Wed Dec 18 18:31:48 UTC 2013

On 12/18/2013 11:26 AM, Drew Tomlinson wrote:
> On 12/17/2013 3:56 PM, Matthew Pherigo wrote:
>> Hi Drew!
>> Believe it or not, systemwide bashrc sourcing isn't actually built-in
>> to bash by default (though in my opinion, it should be). This behavior
>> of global config sourcing actually comes from default /etc/profile
>> files that come with Linux distros. Since FreeBSD uses csh/tcsh by
>> default, of course, it comes with no such thing. However, it's fairly
>> easy to add. The following snippet of code goes into your /etc/profile:
>> if [ "$PS1" ]; then
>>    if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
>>      if [ -f /usr/local/etc/bash.bashrc ]; then
>>      fi
>>    fi
>> fi
>> If the shell is interactive, is a bash shell, and the file
>> /usr/local/etc/bash.bashrc exists, it sources it.
>> This is the snippet of code I use; I think it was originally from Debian.
>> --Matt
> Hi Matt,
> Thanks for your reply.  The snippet of code you provided does work.
> However, I remain confused.
> I have a box I built a couple of years ago which is currently at 9.1.  I
> don't recall how I got bash login scripts working on that one but it
> appears that I put my commands in /usr/local/etc/bashrc. The
> /etc/profile on that box is the default where everything is commented
> out.  So no code is needed on that box to get the commands in
> /usr/local/etc/bashrc to run when logging in.
> I'm just trying to understand why the /etc/profile trick is required on
> this new box I built but not the old?

There's a compile-time option in config-top.h ("#define SYS_BASHRC 
..."), which nobody seems to use.

Back when we used to build our own bash from tarballs for long-gone 
proprietary unix systems, I always used to set these options. It was a 
huge PITA that the prebuilt packages on linux don't have this set and 
for a while we built our own custom version with the feature re-enabled 
but eventually it began to feel too much like swimming upstream. I guess 
we gave up this issue on FreeBSD as well! I still don't understand why 
bash people don't see the value in this feature - having to insert that 
snippet into everybody's personal bashrc is just stupid IMO...

Graham Allan - allan at - (612) 624-5040
School of Physics and Astronomy - University of Minnesota

More information about the freebsd-questions mailing list