# Bash Login Profile Read Order



## daBee (Aug 10, 2017)

I rely on a bunch of aliases and directives in my user (admin) ~/.bash_profile.  I quite often have to enter superuser to get some stuff done efficiently.  I would like to `source /home/rich/.bash_profile` but I am having no luck finding which file to shove that directive in for it to happen upon logging in as superuser.  

I tried ~/.profile, ~/.bashrc.  I can't use ~/.bash_profile as I've symlinked to /home/rich/.bash_profile.  None of these are working.

So this is all through SSH, so:  `local =SSH=> server as admin =su=> superuser`

Any insight appreciated.  Cheers


----------



## daBee (Aug 10, 2017)

It seems anything in /etc takes higher priority than any user .bash_profile so that would take higher precedence.  That would reload ~/.bash_profile, and could mess up my original admin login.  I've tried multiple references to source the admin original, and none of them seem to load.  I just don't want to screw up the original admin login.  I thought FreeBSD might have some specifics that I didn't know about, so I'm posting here.


----------



## daBee (Aug 10, 2017)

OK, created .bshrc, deleted .bashrc, same issue.  Didn't even load .profile reference either.  Nothing is being read.  Both shells are BASH.


----------



## Wozzeck.Live (Aug 10, 2017)

I come back as I have switched temporarily my account to bash
In my wide config all is set to fr_FR.UTF-8 (LC_ALL, LANG, LANGUAGE)

So I have created in ~

.bash_profile and added

```
export BASHPROFILE="OK"
export LC_ALL=en_GB.UTF-8
```

.profile and added :

```
export LANG=en_US.UTF-8
```

.bshrc and add

```
export BSHRC="OK"
```

logout, login, `printenv`

```
LANG=fr_FR.UTF-8
LC_ALL=en_GB.UTF-8
BASHPROFILE="OK"
```

Conclusion :

- Bash reads /etc/profile but ignore ~/.profile (probably used by sh)
- .bshrc is not used in FreeBSD (no BSHRC="OK") unless adding a command in .bash_profile to read ~/.bshrc
- ~/bash_profile works and overrides wide config

Bash 4.4.12_2 built from port with the following options :

COLONBREAK = yes
DOCS = yes
FDESCFS = yes
HELP = yes
STATIC = NO
SYSLOG yes


----------



## scottro (Aug 10, 2017)

I find it works best for me, both locally and remotely, on FreeBSD, to put it all in .bashrc and have a  .bash_profile that reads

```
source ~/.bashrc
```
Then it uses ~/.bashrc as expected.   I don't remember what wasn't working for me to start using this method, but it works well for the various aliases and such that I use.


----------



## SirDice (Aug 10, 2017)

This is better, it won't produce an error in case ~/.bashrc doesn't exist. This is also how it's done on most Linux platforms.

~/.bash_profile:

```
if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi
```


----------



## daBee (Aug 11, 2017)

Thanks for the testing.  I just did the same, and some odd stuff is happening:

in .bashrc I entered an alias for a simple echo, and exported an environment variable that was simple.  The variable showed up in `env`, but the alias didn't.  

Tried .bshrc and nothing showed up using `env`.  

My observations:  .bashrc is partially loaded after login to `root`.  Truly odd.  


```
===> The following configuration options are available for bash-4.4.12_2:
     COLONBREAKSWORDS=on: Colons break words
     DOCS=on: Build and/or install documentation
     FDESCFS=off: Enable use of /dev/fd
     HELP=on: Enable builtin help
     NLS=on: Native Language Support
     STATIC=off: Build static executables and/or libraries
     SYSLOG=off: Syslog logging support
```



Wozzeck.Live said:


> So I have created in ~
> 
> .bshrc and add
> 
> ...


----------



## daBee (Aug 11, 2017)

More strange behaviour.  In .bashrc I tried this to test for /home/rich/.bash_profile then source that very same file, it works.  Then I tried directly sourcing /home/rich/.bash_profile...and it now works.  

Either I missed something or it's behaving poorly for some unknown reason.  In any case, it works now and I thank everybody.  




SirDice said:


> This is better, it won't produce an error in case ~/.bashrc doesn't exist. This is also how it's done on most Linux platforms.
> 
> ~/.bash_profile:
> 
> ...


----------

