Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

First, it's .bashrc and /etc/bashrc.

http://www.gnu.org/software/bash/manual/html_node/Bash-Start...

.bashrc - is for non-login shells (not run with --login option). This is where you want to configure your PATH, so all shell invocations behave the same. You'll likely have the PATH modification as the first line, then you may want to source the system rc file (/etc/bashrc), and, usually, you'll have some interactive-only modifications such modifications to PS1.

.bash_profile(, .bash_login, or .profile) - is used for login shells. You may have some reason to run some commands (personal MTOD!?). There may be good reason to manipulate PATH here, but I can't think of one. (The rbenv tool from the Ruby community insists using .bash_profile; I don't know why.) Finally, you end by sourcing the .bashrc.



Environment variables are automatically shared from a parent process to its child processes, so typically you'd want to set up your environment in ~/.profile (or ~/.bash_profile) so you only have to do the work once. This includes things like setting $PATH, $LESS, $EDITOR, $LS_COLORS and so forth.

On the other hand, things like shell aliases are not automatically shared to child processes, so you need to set them up afresh in every shell you launch. Therefore, ~/.bashrc is the place for those things.


> typically you'd want to set up your environment in ~/.profile (or ~/.bash_profile)

It's an early optimization, that generally no longer is worth the complexity. I put everything in .bashrc. I'm more likely to break out a separate environment shell file by related or complex tasks to assist in testing/debugging my environment.


Thanks for the clarification and highlighting my point with the comment about rbenv. I think I found the source of my confusion which is (http://www.joshstaiger.org/archives/2005/07/bash_profile_vs....) "An exception to the terminal window guidelines is Mac OS X’s Terminal.app, which runs a login shell by default for each new terminal window, calling .bash_profile instead of .bashrc. Other GUI terminal emulators may do the same, but most tend not to.".

That may explain why so many github projects recommend adding PATH and other env variables to .bash_profile.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: