problems with .bashrc

Viktor Lazlo viktorlazlo at telus.net
Tue Apr 13 20:01:34 PDT 2004


On Tue, 13 Apr 2004, fudo wrote:

> I'm new to FreeBSD, and to bash. I'm running FreeBSD 5.0, and added
> bash from the cd during install. There are .profile and .shrc files in
> my home directory; .profile references .shrc with ENV=$HOME/.shrc;
> export ENV. There are several uncommented alias lines in the .shrc
> file, but none of them work. From what I've read, bash should read
> .profile and .shrc, but just in case, I tried copying them to
> .bash_profile and .bashrc, changing ENV to =$HOME/.bashrc, and renaming
> the original files, but the aliases still don't work. Aliases are
> formatted: alias ll='ls -laFo'; entering that at the prompt and it
> works fine. Seems like bash isn't reading the rc file. Obviously, I'm
> missing something; any suggestions appreciated. Thanks.

I think what is happening is the aliases in .shrc are not read directly by
bash unless invoked as sh, and the .shrc assigned to ENV is only read for
non-login shells; I'm not sure why they wouldn't work when entered in
.bash_profile, but the fact that they don't suggests a conflict between
the files the commands are entered in and the order in which they are
read.

When invoked as bash (not sh) the start-up files that bash reads for a
login shell are, in order:

  i) /etc/profile

and then the first of any of the following that exists:

 ii) ~/.bash_profile OR
iii) ~/.bash_login OR
 iv) ~/.profile

Non-login interactive bash shells (when changing or starting new shells
during a session) read only ~/.bashrc.

Non-login non-interactive bash shells (ie-when launched from inside a
script) check the startup file in $BASH_ENV, or $ENV if that doesn't
exist.

An easy way to make sure all three invocations of bash reference the same
start-up file is:

 i) use .bashrc as your customized startup file

ii) create a .bash_profile containing only:

        export BASH_ENV=~/.bashrc
        if [ -f ~/.bashrc ]; then source ~/.bashrc; fi

This way, after reading /etc/profile a login shell will read the first
file found, ~/.bash_profile, which in turn reads ~/.bashrc

Non-login interactive shells will read ~/.bashrc as usual

Non-login non-interactive shells will read the ~/.bashrc assigned in
$BASH_ENV.

Cheers,

Viktor


More information about the freebsd-questions mailing list