Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Possible Duplicate:
When should I put configurations into .bashrc vs into. .bash_profile?

I am a n00b when it comes to working in Linux env and would like to know the purpose of .bashrc and .bash_profile. I only know that they are specific to each user account. What features/behavior can be added/modified by implementing something in these files

share|improve this question

marked as duplicate by RedGrittyBrick, slhck, studiohack May 18 '12 at 21:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
Everyone is born as n00b. But the next step after that is to do man bash. I know it's a whole lot of text, but it's worth it. –  ott-- May 18 '12 at 18:12
2  
-1 This question shows no research effort. It's exhaustively explained in man bash's section INVOCATION (paragraphs 4 and 6 for me). –  Daniel Beck May 18 '12 at 19:02
    
Also: Difference between .bashrc and .bash_profile (probably that more than the other) –  slhck May 18 '12 at 19:04

2 Answers 2

up vote 3 down vote accepted

First, .bash_profile is used for login bash shells only. .bashrc is used for every OTHER bash shell. Therefore, .bash_profile will typically source .bashrc if it exists so you don't have to duplicate any commands you want to run for every shell whether it was a login shell or not.

Generally speaking, there are two things you do with these scripts: Run programs and set environment variables. Anything you want to run when you log in, you put in .bash_profile, anything you want to set on every shell (for instance, if you use screen or open a terminal) you put in .bashrc.

Some things from my own .bashrc (as an example):

  • Set $PS1
  • Enable special tab completion rules
  • Set shell options by running shopt
  • Set up command aliases

From my .bash_profile:

  • Source .bashrc
  • Add directories to $PATH
  • Run ssh-agent

It's important to note that .bash_profile is only executed if you're directly logging in to a bash shell. If you're starting an X session, you're logging into the X server which will have its own login script (typically something like .xsession)

share|improve this answer

It's all explained in the Bash Manual in the section titled "Bash Startup Files": http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files

UPDATE: Here's the short version:

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc, if that file exists.

When Bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute.

share|improve this answer
2  
Please add more to your answer then just a link. I am not saying the link is bad, but a quick summary would be a lot better. –  Zoredache May 18 '12 at 18:36
    
@Zoredache OK, I updated my answer with a short summary of what the manual says. –  Fran May 23 '12 at 16:47

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