1

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?

3

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.

  • could someone tell me why my answer got a downvote? – binhsonnguyen Mar 18 '16 at 4:34
  • That didn't work for me. (I didn't downvote) – relidon Mar 18 '16 at 4:46
  • First, we confirm that your .bashrc sourced automatically on your new terminal session. You can try to add to .bashrc a simple alias like alias myEcho='echo Anubeloredelana', which print Anubeloredelana onto the terminal, and in a new terminal session try to call it to see if it work. – binhsonnguyen Mar 18 '16 at 5:00
  • 1
    The answer given by @Mark here is 100% correct -- Terminal sources ~/.bash_profile, not ~/.bashrc. Double check that you added the correct lines to your ~/.bash_profile? – Ian C. Mar 18 '16 at 5:01
  • 1
    FIXED! after you told me to add if [ -f ~/.bashrc ]; then . ~/.bashrc fi I realised I was adding it in both ~/.bashrc and ~/.bash_profile. Now it works. I can't upvote (not enough reputation) but thanks for your help @binhsonnguyen – relidon Mar 18 '16 at 5:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .