Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

bash won't source .bashrc from an interactive terminal unless I manually run bash from a terminal:

$ bash

or manually source it:

$ source ./.bashrc

or running:

$ st -e bash

Here's some useful output I hope:

$ echo $TERM
st-256color

$ echo $SHELL
/bin/sh

$ readlink /bin/sh
bash

$ shopt login_shell
login_shell     off

I'm on CRUX Linux 3.0 and I use dwm and st. I've tried using .bash_profile and .profile with no success.

Any ideas?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

Why would it source it? You are not running true bash:

$ echo $SHELL
/bin/sh

In most modern systems sh is a symlink to a basic shell. On my Debian for example:

$ ls -l /bin/sh 
lrwxrwxrwx 1 root root 4 Aug  1  2012 /bin/sh -> dash

In your case, sh is a link to bash but, as explained in man bash:

If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. [...] When invoked as an interactive shell with the name sh, bash looks for the variable ENV, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked as sh does not attempt to read and execute commands from any other startup files, the --rcfile option has no effect.

and

--norc
Do not read and execute the system wide initialization file /etc/bash.bashrc and the personal initialization file ~/.bashrc if the shell is interactive. This option is on by default if the shell is invoked as sh.

So, since your default shell is sh, .bashrc is not read. Just set your default shell to bash using chsh -s /bin/bash.

share|improve this answer
    
Thank you. I assumed it didn't matter since /bin/sh pointed to /bin/bash. I suppose this issue stemmed from not explicitly assigning the shell to /bin/bash when I originally created the user account. –  haste Oct 10 '13 at 18:56
    
Also, Debian/Ubuntu switched to dash for /bin/sh as part of the effort to reduce startup time. This was hilarious when my users started asking why their shell acted differently. –  kurtm Oct 10 '13 at 20:14

In .bash_profile make sure you have the following:

# .bash_profile

# If .bash_profile exists, bash doesn't read .profile
if [[ -f ~/.profile ]]; then
  . ~/.profile
fi

# If the shell is interactive, get the aliases and functions
if [[ $- == *i* -f ~/.bashrc ]]; then
    . ~/.bashrc
fi
share|improve this answer
    
@terdon Your answer is the correct one. My answer would only be valid if he was running bash. Nice catch, I missed that. –  Jeight Oct 10 '13 at 18:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.