Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should the .bashrc in the home directory load automatically?

Tags:

bash

macos

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"
like image 995
Andy Avatar asked Mar 31 '12 04:03

Andy


2 Answers

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
like image 176
kev Avatar answered Oct 05 '22 22:10

kev


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"
like image 23
A B Avatar answered Oct 06 '22 00:10

A B