9

I added scala in my .bashrc file, but when I shut off my mac and turn it back on it does not find it. When i do

source ~/.bashrc 

all is back to normal. I would say the issue is with the whole file in general, but the problem, is I have other things in there that have worked just fine before, but the problem is persistent with scala. Anybody know why this is and explain why I am getting the problem? This is whats in my .bashrc file, which runs rvm and mysql correctly, but not scala:

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
export PATH="/usr/local/mysql/bin:$PATH"
export PATH="/Users/Zeroe/scala-2.9.1-1/bin:$PATH"
Andy
  • 10,553
  • 21
  • 75
  • 125
  • 2
    See [here](http://apple.stackexchange.com/questions/12993/why-doesnt-bashrc-run-automatically). – ughoavgfhw Mar 31 '12 at 04:34
  • Hmm, thanks a lot for the link. I will try it when I get a chance. Definitely put it as an answer so I can accept it if it works. – Andy Mar 31 '12 at 04:39

2 Answers2

54

I figured out this diagram by adding echo "${BASH_SOURCE[0]}" to those scripts.

                     +-----------------+   +------FIRST-------+   +-----------------+
                     |                 |   | ~/.bash_profile  |   |                 |
login shell -------->|  /etc/profile   |-->| ~/.bash_login ------>|  ~/.bashrc      |
                     |                 |   | ~/.profile       |   |                 |
                     +-----------------+   +------------------+   +-----------------+
                     +-----------------+   +-----------------+
                     |                 |   |                 |
interactive shell -->|  ~/.bashrc -------->| /etc/bashrc     |
                     |                 |   |                 |
                     +-----------------+   +-----------------+
                     +-----------------+
                     |                 |
logout shell ------->|  ~/.bash_logout |
                     |                 |
                     +-----------------+

Note

  1. []-->[] means source by workflow (Automatically).
  2. [--->[] means source by convention (Manually. If not, nothing happen.).
  3. FIRST means find the first available, ignore rest
kev
  • 155,172
  • 47
  • 273
  • 272
  • That is truly a great answer. – Daniel Kamil Kozar Mar 31 '12 at 08:39
  • 3
    Nice picture - much better than the wall of text docs usually seen on this stuff. – Michael Burr Apr 07 '12 at 06:47
  • 2
    A few notes: "interactive shell" should be "interactive, non-login shell", and "login shell" should be "interactive, login shell". Also, at least on Ubuntu, for non-login, interactive shells, `/etc/bash.bashrc` is read first, then `~/.bashrc`. Note that `/etc/bash.bashrc` is not in vanilla GNU Bash, it's a modification that a lot of distros do. – philb Dec 08 '20 at 16:30
11

Your shell is probably a login shell, in which case bash will read various profile files in order:

  1. /etc/profile
  2. ~/.bash_profile
  3. ~/.bash_login
  4. ~/.profile

It's typical to source ~/.bashrc from one of those files so you get the same config for login shells as well.

This is what my ~/.profile contains:

# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
# see /usr/share/doc/bash/examples/startup-files for examples.
# the files are located in the bash-doc package.

# the default umask is set in /etc/profile; for setting the umask
# for ssh logins, install and configure the libpam-umask package.
#umask 022

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
export LANGUAGE="en_US:en"
export LC_MESSAGES="en_US.UTF-8"
export LC_CTYPE="en_US.UTF-8"
export LC_COLLATE="en_US.UTF-8"
A B
  • 8,340
  • 2
  • 31
  • 35