MacOS – Why don’t changes in the bashrc file work on a new terminal window

aliasbashcommand linemacosterminal

I'm trying to add an alias to the bashrc file. Since I'm not good at this, Im' going to write all the steps I took

nano ~/.bashrc

The file had this in it

export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting

On top of that I added my alias

dropUpload(){
~/drop.sh upload $1 $2
}
alias dropU=dropUpload

Saved the file and then sourced it with . ~/.bashrc

In the same window I tried using the code dropU first/url second/url and it worked. I closed the terminal window and opened a new one, the code no longer works. The error I get is

-bash: dropU: command not found

If I nano back to the file my new code is there. If I re-source the file, the code works. How can I get this to persist?

Best Answer

in my ~/.bash_profile have this code

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

@Mark have a greate answer here.

I found a link that clear that case at Unix FAQ for OSX.

It wrote

Bash Startup Files

When a "login shell" starts up, it reads the file "/etc/profile" and then "~/.bash_profile" or "~/.bash_login" or "~/.profile" (whichever one exists - it only reads one of these, checking for them in the order mentioned).

When a "non-login shell" starts up, it reads the file "/etc/bashrc" and then the file "~/.bashrc".

Note that when bash is invoked with the name "sh", it tries to mimic the startup sequence of the Bourne shell ("sh"). In particular, a non-login shell invoked as "sh" does not read any dot files by default. See the bash man page for details.