Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I added this line into my ~/.bashrc file.

alias myserver='ssh davidfaux@davidfaux.com'

However, when I open terminal and run myserver, terminal complains that

-bash: myserver: command not found

When I source my .bashrc file, however, (. .bashrc), the alias works.

Nonetheless, I do not want to source the file every time I open terminal for the alias to work. How do I make that happen?

share|improve this question
3  
This comment explains the reason for this. That question tells you how to fix it. –  ughoavgfhw Mar 4 '12 at 19:35
    
Thanks a lot! I did not know that starting the shell executes those files in order. Indeed, adding . .bashrc into .bash_profile works. –  David Faux Mar 4 '12 at 19:43
    
@ughoavgfhw can/should you change your comment to an answer? That way it can be marked as an answer. –  soxman Mar 5 '12 at 14:14
add comment

1 Answer

up vote 5 down vote accepted

In short you are putting your aliases in the wrong file .bashrc, that is why you need to keep running source to get the aliases working in any new login terminal instances.

By default, Terminal starts the shell via /usr/bin/login, which makes the shell a login shell. On every platform (not just Mac OS X) bash does not use .bashrc for login shells (only /etc/profile and the first of .bash_profile, .bash_login, .profile that exists and is readable). This is why “put source ~/.bashrc in your .bash_profile” is standard advice. – Chris Johnsen

For More information see the manual page for bash. Then look under the INVOCATION section.

man bash
share|improve this answer
    
Do I need to reboot in order to get things working? Because I added source ~/.bashrc to my .bash_profile, but I'm still facing the same issue... –  Michiel Jan 7 at 9:35
    
No in most cases you just need to open a new terminal window for the changes to take effect, the changes will only take effect in the newly opened window. –  MrDaniel Jan 9 at 2:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.